I've used call_group
to accomplish a similar thing. All the objects have to belong to the group you specify, but you can easily call a method on all the objects in the tree that are that group.
Here's how I update the speed on all the "traffic cars" in my game.
get_tree().call_group_flags(0, _g.TRAFFIC_GROUP, 'set_speed', new_speed)
I don't know what the 0
does, but in all the places where I'm using it, I pass 0
. You can use call_group
instead of call_group_flags
I think, then you don't have to pass 0
. Everything after the 3rd parameter gets passed to the method that is called. So you can actually pass any number of parameters to call_group_flags
Disclaimer: I'm actually using call_group and passing 3 things but I think that is a bug in my code that is leftover from porting to 3.0. I have to fix it but didn't want to hold up this response while I re-test my entire game.