While the game runs, items will be spawned, so a new Node “ItemWave” is being spawned which contains continuously spawned items. You can see the resulting tree in the example in Screenshot 2.
Please ignore that I didn´t add collision shapes since its just an artificial example.
Now when the item area detects the “Player” area, I want to send a signal from the item up to the “Player” node. It would be also ok to send it up to the “GameLevel” node. Please note that the Item node doesn´t belong to the scene at the start of the game.
If you want to pass info you should add it into your signal manager like this:
# in signal_manager
signal signal_from_item(ItemScene: Node)
# in item scene
SignalManager.signal_from_item.emit(self)
# in Player scene in collecting function
func _on_signal_from_item(ItemScene: Node):
# Do whatever here
Using the signal manager means your emitting from item will work even when running your item scene by itself. The same for your player, who will always be able to connect to the signal_manager, even if no items exist yet.
Hope that helps and makes sense.
PS Another way to do this is to add a reference to your Player node that you set when you are instantiating the item scene. Then you can just use the player reference to communicate to that node. This is not as robust as using signals though so would recommend the signal_manager.
PPS People often call this a ‘signal bus’, but I prefer the name ‘signal_manager’. You can call it whatever suits you of course.
Thank you Paul. Need to go back to work now but I will try it out later!
To be honest I am surprised about the approach. I thought the approach would be something like get_node(“Player”) etc.
This never worked for me. Your approach seems much more reasonable and Chat GPT already explained to me that it is a very robust approach
This is a fairly common approach to signalling between components and still maintaining a good separation of concerns. You don’t need every signal you use to be in the signal manager (I have made that mistake in the past) just ones where like in your case you are not sure if the nodes that originate the signals are available or not.