Area2D on_body_entered not emitting

Godot Version

R4.3

Question

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.

I’ve checked the collision layers:

Body:

Area:

I’ve checked the signal connection:

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?

1 Like

I think the issue is that StaticBodies are supposed to be static,and if you move them by changing their position collisions wont work as expected.

Try replacing the static body with a rigidbody2d,characterbody2d or mb another area2d

2 Likes

@shetburd_0 StaticBody2D inherits from PhysicsBody2D, which is what should trigger the body_entered signal.

However I also tried changing it to area now, but had no luck, it’s still not working. :confused:

ok i take that back. It works now. As I was changing it to Area2D the collision layers got reset, so the detection didn’t work.

however I’m still curious, the documentation says the following for the signal:

Emitted when the received body enters this area. body can be a PhysicsBody2D or a TileMap.

And for PhysicsBody:

Inherited By: CharacterBody2D, RigidBody2D, StaticBody2D

So shouldn’t it trigger the event?

1 Like

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”.

1 Like

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. :slight_smile:

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.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.