Apply change to all nodes that name start with "Enemy"

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Chevi

My code works fine with one enemy entity but as soon as I bring in an “Enemy2” my “get_node(”…/Enemy)" doesn’t work on the “Enemy2” can I do something so it gets all nodes that start with “Enemy” in their name?

:bust_in_silhouette: Reply From: klaas

a simple method would be to use groups. Add your enemies to a group using the editor or with

enemy.add_to_group ( "enemies" )

then call elsewhere

var array_of_nodes = get_tree().get_nodes_in_group ( "enemies" )

But is there a way to get an area node from said groups?

Chevi | 2020-07-21 19:31

Any node can be put in groups.
But maybe i dont understand correctly what your asking.

klaas | 2020-07-21 19:34

You can loop through the array that Klaas has given you and do what you like with it.

for _i in array_of_nodes:

deaton64 | 2020-07-21 20:50