Collisions dont occur between (some) bodies instanced in same frame

Godot Version

4.3 dev1 (Also tested on 4.2)


I’m having an issue that I have no idea how to move forward with and fix. None of the collision areas on a CharacterBody2D scene detect the collision body of a StaticBody2D, but only if the areas are overlapping and if scenes were added to the scene tree in the same frame. This includes the collision shape, and two child Area2Ds acting as detection ranges for the character scenes. If the static scene is instanced later, the collision occurs (mostly) as expected.

I’ve checked the obvious stuff: The collision layers and masks are all set up properly, monitoring and monitorable are enabled for the areas, and I’ve tried setting the disable mode to keep active in all instances.

I know this is specifically a case of collisions/detection not occurring, since the get_overlapping_bodies() function for the area2Ds returns nothing even if they are overlapping a body with the appropriate layer.

I’m printing the result of get_overlapping_bodies() to a label in the physics process callback

Note: The character bodies have two area2Ds, while the static bodies only have one.

Here, the static body and character bodies are in one another’s detect areas, but only the static body sees them. If a new, identical static body is instanced, the character bodies can see it, but not the first one.

If the gamestate is saved and loaded (the reason I ran into this issue), the character bodies remember their target destination, but no longer detect or collide with the static body. They do collide with each other, and they detect a newly instanced static body.

Same thing, but with visible collision shapes

If the character bodies are added to the layer mask of their own area2Ds, they correctly detect themselves upon entering the scene tree.

Lastly, while the character bodies usually detect a new static body instance as expected, sometimes it doesn’t happen immediately, causing a strange delayed detection.

I tried to create a minimal reproduction project with a similar physics body setup, however, I couldn’t reproduce this kind of inconsistent behavior, with the detection occurring immediately as expected. Also, haven’t shown it here, but the character bodies collide with the collision layer of a tilemap as expected under all circumstances.

So yeah, no idea what to do next, any help or advice is appreciated.

I think I’ve found a workaround that was also suggested in a bug report on github in relation to area2D collision detection (can’t find the exact page anymore), but using set_collision_mask_value for the layers that need to be detected seems to force a re-check, causing the bodies to appear properly.

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