Sending function to all children of a node

Godot Version

v4.2.2

Question

I am trying to send a function to all the children of a specific node.
There is no guarantee how many children this node will have, so I created a for loop.
But I get an error:

Line 28:Cannot find property “Chain_Explosion” on base “Array[Node]”.
Line 28:Function “Chain_Explosion()” not found in base Array[Node].

script:

for send_Explosion_Signal in get_child(3).get_children():
	get_child(3).get_children(i).Chain_Explosion()

I don’t know why it wouldn’t let me do this if the node I am calling will always have that function, especially since “get_parent().get_parent().Game_over()” has already been allowed.

Any suggestions would be greatly appreciated.

This assigns send_Explosion_Signal to each of the children in your 4th node. Use that iterator, might be better practice to use $NodeName or get_node instead of get_child

for send_Explosion_Signal in get_child(3).get_children():
    send_Explosion_Signal.Chain_Explosion()

You could try using Node.propagate_call()

1 Like