How can I receive the same signal from multiple instances of the same scene

I currently am trying to have a system with trees that emit a signal when they are hit. However only one of the trees work with the signal, since the other scene have to be referred as Tree, Tree2, Tree3… How can I make a node receive the same signal for multiple instances?

Are you dynamically creating trees? Do you mean you are adding the trees with a readable name, can you connect the signal after instantiation?

I think I would do it like this:
Assuming trees emit signal “hit” when they get hit…
I would add a “tree” group to the trees
The main script would look like this:

extends Node

func update() -> void:
      for tree in get_tree().get_nodes_in_group("tree"):
          tree.hit.connect(on_tree_hit)

func _ready() -> void:
     update()

func on_tree_hit() -> void:
     print("tree got hit!")

I hope this will be helpful!

2 Likes

It Instances trees randomly throughout the playtime of the game.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.