I'm not sure if you have seen this, but looking at the documentation for the Area2D
, I saw it has the signals area_shape_entered
and body_shape_entered
. Both give the following values:
area_shape_entered
:
( int
area_id, Area2D
area, int
area_shape, int
self_shape )
body_shape_entered
:
( int
body_id, Node
body, int
body_shape, int
area_shape )
I'm going to speculate with the area_shape_entered
, but it should also apply to body_shape_entered
. Based on the (honestly lackluster) descriptions for these two signals, it seems that "area_id
" is the instance ID of the Area2D that entered the signal owner. The "area
" is the Area2D instance itself; I don't know why they have these two values given by the signal. The "area_shape
" is the index of the CollisionShape2D of the invading Area2D shape. The self_shape
is the index of the CollisionShape2D of the signal owner.
Say you have two Area2D
nodes, one named "A
" and the other named "B
". A
has only one CollisionShape2D
as a child; and B
has four CollisionShape2D
nodes as its children. B
also has its signal area_shape_entered
connected to some other node's script.
A
is walking around, and happens to enter B
so the two are intersecting, specifically the second CollisionShape2D
child of B
. B
sends out its area_shape_entered
signal and the connected function receives the following information:
(1184, [Area2D:1184], 0, 1)
Now, the 1184
and [Area2D:1184]
are both temporary placeholders for the sake of this explanation -- these values can and will change during code execution.
So, what does this tell you?
Well, 1184
is the Instance ID of A
; it is given as an integer.
[Area2D:1184]
is A
itself.
The 0
is the index of the CollisionShape2D
child of A
; since A
only has one child, which is CollisionShape2D
, this value will always be zero. Of course, if there are other children of A
, this value may change depending on where the CollisionShape2D
is located, so keep that in mind.
And finally, the 1
-- this is the index of the CollisionShape2D
child of B
(hence why it is given the name "self_shape
"). Like above, if this CollisionShape2D
is anywhere else, its index value will change, so remember that.
The signal body_shape_entered
will give similar information, however, instead of A
being an Area2D
itself, it is a RigidBody2D
, KinematicBody2D
, or a StaticBody2D
(though you shouldn't move Static Bodies willy-nilly).
I hope this was helpful, and that it makes sense.