I'm creating a custom plugin for my game, and I created a script that extends
Spatial so I can add it to the scene tree.
What this script is supposed to do is create two
Area nodes with accompanying
SphereShapes (the first larger than the second). I then add the
Area nodes as children of the script itself and connect the first
area_exited(area) signals through code. The script is supposed to be instantiated multiple times, each one looking out for the others. The first
Area looks for the second, smaller
Area of the other instances; I use signals to figure out who is seen or not.
However, when I create multiple instances of the script and add to the scene tree, only the last to be created will have its
Area's signals work.
Here is the
_init function of the script:
func _init(_object : Spatial = null) -> void:
name = "RegionObject"
object = _object
detector_area.name = "DetectorArea"
detector_area_col_shape.shape = detector_shape
detector_area_col_shape.name = "DetectorShape"
detector_shape.radius = detector_shape_radius
print("Connecting RegionObject signals")
detection_area.name = "DetectionArea"
detection_area_col_shape.shape = detection_shape
detection_area_col_shape.name = "DetectionShape"
detection_shape.radius = detection_shape_radius