#how do we get the nodes in global groups?
1 messages · Page 1 of 1 (latest)
@low fractal you have to call it from within something like _ready() or _process() functions
calling it at the top level there will try and run get_tree() on the node before it actually enters the tree, so it will not be able to do so
that might work, you'd have to try it out
what error?
I had to specify that its player[0].variable not just player.variable
Your 'player' var is now an Array of all nodes in your 'Player' group.
If you added more nodes to that same group, you could mistakenly get the incorrect object by accessing the player array by index.
You can get the name of the node from the 'player' Array easily enough:
print(player[0].name)
Not sure that creating a group for a single Node is the best way to access your Player node (that reminds me, you are gonna get yourself a little mixed up using very similar vars names for this. For example, your 'player' array stores your objects from your group. Then you have 'Player' as the Group name, and 'Player' as your scene Node name.
A group could be used to change the property of multiple objects at once, like 'visible = false', or calling a method on them all. Typically, to hide or enemies, or something like that.
I may be incorrect, still very new at all this myself.
Groups are quite performant as long as you’re not constantly looping through them(and I mean large and basically process calls) even then they’re not that bad when used correctly, they allow for more decoupling which can be better or worse.