- Edited
Hi, I am trying to recreate a common aviation scenario, where an aircraft flies into detection range of a radar, and the receiver on the aircraft captures the characteristics of the waves that it emits. I have individual scenes for the aircraft and radar. In my test scenario, the aircraft is called "Entity1" and the radar is "Emitter". My testing scene is a 2D node called "First". The Emitter has a custom signal called entity_in_scan_range that is emitted if my aircraft enters its ScanRange node, which is an Area2D. This signal is captured in "First", which then forwards some properties of my Emitter object to the aircraft's receiver.
I am able to create this basic scenario, but for each Emitter, I have to connect its signal to "First". Is there a more automated way to do this? I would like to have every Emitter instance's signal connected to the parent node without having to manually connect them when I place them on the level. I believe I can use the .connect() method in code to do this, but I do not think I fully understood its usage.
I have added screenshots, which will hopefully make what I am attempting to do much clearer.
The "First" scene:
Script for "First":
The "Emitter" scene:
The script for "Emitter":
Seems to work when signals are manually connected:
How I'm trying to connect the signal (this is the emitter.gd script):
Method in "First" that I'm trying to call on capturing the signal:
However, this throws an error that says:
"Invalid type in function 'connect' in base 'Signal'. Cannot convert argument 1 from Nil to Callable."
EDIT (AN UPDATE):
If I duplicate my instantiated Emitter in the "First" scene and change its properties, I don't have to manually connect the signal to "First", but I do if I instantiate another "Emitter". This brings me to three questions:
Is it hence better to duplicate scene instances instead of creating new ones if I want to have a common communication channel between the parent and child nodes? This way I don't need to have <X> different methods for capturing the signals from <X> different instances of the same object type.
Why does this work?
What am I doing wrong here? What would instead be the correct way to use .connect() instead of the way I have used it?