I am making a custom plugin that has a RegionObject
script which extends Spatial
; I put class_name RegionObject
at the top of the script file.
What this script is supposed to do is create two Area
nodes with their own accompanying CollisionShape
nodes and SphereShape
s (The CollisionShape
nodes are children to the two Area
nodes, one to each). The first Area
/CollisionShape
/SphereShape
are the largest, and look out for the second, smaller Area
/CollisionShape
/SphereShape
of other instances of the script. In the script's _init
function, I connect the first Area
's signals area_entered(area)
and area_exited(area)
to separate functions at the bottom of the script file. The enter signal and exit signal functions have print("Area entered: ", area)
and print("Area exited: ", area)
, respectively.
During testing, I created two instances of this script and added them to the scene tree. When moving one of them around, only the second instance, the one added last, has its signal functions called, despite both having their functions connected in the _init
function.
Here is the RegionObject
_init
function code:
func _init(_object : Spatial = null) -> void:
name = "RegionObject"
add_to_group("RegionObjects", true)
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
detector_area.add_child(detector_area_col_shape)
add_child(detector_area)
print("Connecting RegionObject signals")
detector_area.connect("area_entered",
self,
"_on_detector_area_entered")
detector_area.connect("area_exited",
self,
"_on_detector_area_exited")
detection_area.name = "DetectionArea"
detection_area_col_shape.shape = detection_shape
detection_area_col_shape.name = "DetectionShape"
detection_shape.radius = detection_shape_radius
detection_area.add_child(detection_area_col_shape)
add_child(detection_area)
If anyone has any idea why this is happening, and possibly have a way of fixing this issue, please let me know. Thank you!