godot: Nodes shouldn't be added to 'idle_process' group
I don’t know if this is a new thing in v2.1.2, but I just noticed that nodes are added to this ‘idle_process’ group internally. This is a flaw in the design. Only groups added by the developer should be present at run time. If you add a node to only one group then you expect that the node will have only one group at run time and might think to retrieve that with self.get_groups()[0]
or something like that. Because godot internally adds some nodes to ‘idle_process’, the above action can lead to errors.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 2
- Comments: 27 (16 by maintainers)
You know @akien-mga after thinking about it a bit more. I kind of prefer getting the info from the groups. Here’s why. Say you have multiple resources, some start with ‘enemy’, some start with ‘this’ some with ‘that’ etc. You get the idea. If you spread all over the place code like:
You still have to do massive refactoring. Alright, so don’t use hard coded string values, let’s instead use a class variable to store these things… like an array with a specific order. But wait, isn’t that what groups should do in the first place?! So I noticed that the groups mechanism forces an alphabetical order (except for the internal states for some reason, which I think can either go at beginning or at end of the array).
So in the end of it all I think we should have
get_groups(internal=true,false)
as mentioned but also have order in the group array so that would mean enhancing the group panel to allow ordering of groups. They’re arrays after all, not sets or maps or other things and arrays have order to them. Also allow editing in the panel, as of now you can only remove and add groups. So then there would be no problem withget_groups()[0, 1, 2, 3.. etc.]
as the order would be guaranteed to be the one you set.It’s bad practice (IMO) because if you decide to add those enemies to a new “flying” group for flying enemies, your code might break. Writing code that assumes that you’ll hopefully use the right group name to match your node names is hazardous. It’s IMO much better to write one more line and be future proof:
than
I haven’t said anything was wrong with it, I’m just raising questions as so far the discussion has only been about “whooo Godot is spilling its internals all over the floor” 😃
i don’t agree with this. it should rather just be made clear that _ is used for system groups.
On 30/01/2017, Răzvan Cosmin Rădulescu notifications@github.com wrote:
As long as the developer gets only the groups that he himself put in, doesn’t really matter how the internals of
get_groups
works. It’s a good idea to haveget_groups
remove everything starting with_
or maybe even__
in case someone decides for whatever reason to use a group name starting with_
? Doing this wouldn’t change much in terms of the internals of GD