I know this is a common question, but I double checked all pitfalls I know of.
So, I have this StaticBody2D that can be dragged via the mouse over an Area2D. I want the Area2D to then emit the on_body_entered signal, but it doesn’t happen.
Here is my function in the script that the signal is connected to:
func _on_character_area_body_entered(body:Node2D) -> void:
print("body entered")
if body is Die:
print("die entered")
body.current_target_character = self
The body is of my custom class “Die” which extends “StaticBody2D”.
To check if the script is really in the scene, I’ve added a mouse_entered function right below it, which works fine.
Does anybody have a clue what could be wrong here?
I think that StaticBody just works differently than the others when the engine updates collisions,especially when you move the staticbody which is designed to be “static”.
I see! I was under the impression that a static body is not moved by physics, but if I change the position programmatically it doesn’t really matter.
Thanks for your help anyway.
The docs say:
When StaticBody2D is moved, it is teleported to its new position without affecting other physics bodies in its path. If this is not desired, use AnimatableBody2D instead.
This is indeed an interesting question. The way I see it is: even though StaticBody2D inherits from PhysicsBody2D and by default it should have all its properties, as the signal description points out, the node emits the signal only when the received body ENTERS the area. Since static bodies don’t move, they can just teleport, entering as such is not a possible action, meaning it can never enter anything. Therefore it is not possible for it to trigger a signal which listens to the ENTER action.