New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Disabling process of PhysicsBody2D and containing Area2D on same frame will make area register body as entered forever #76219
Comments
Possible duplicate of #61420 |
It seems like the same root cause, but I could be wrong. I saw someone opened a PR to fix it the other day, but I haven't looked into it too much. |
... and I found a bug variant today: disabling and re-enabling Area2D containing PhysicsBody2D on same frame will register PhysicsBody2D forever. To repro, reuse the MWE above and modify toggle_body_and_area to do:
Play, press T, then M to move the body away and notice the count is still at 1 instead of 0. You can also check that waiting 1 frame before the re-enabling:
does not trigger the issue. |
OK, I see how #61420 can be helpful now
Indeed, but I see that the research (esp. hcoura's observations) may in fact be useful for this issue too. |
For now, I used the following workaround in a real project, and it works:
|
… and containing Area2D on same frame will make area register body as entered forever
Partial Fix: GH: godotengine#76219 Disabling process of PhysicsBody2D and conta…
I don't think changing As a very nasty side-effect this bug seems to break games that use |
Issue also occurs for the 3D counterparts, was about to report as a new issue before finding this one. Here's a project reproducing the issue in 3D. Tested in 4.1.1 |
Tested in 4.1.1 with Jolt physics and found no issue. |
I tested the MRP under Godot 4.1.2 with this fix: #81809. The issue was gone. |
Godot version
v4.0.2.stable.official [7a0977c]
System information
Linux Ubuntu 22.04 with Unity desktop
Issue description
I have a Restart functionality in my game that respawns all my characters to their initial positions.
Some of my code uses Area2D.get_overlapping_bodies and the doc says it doesn't take rigibody moves in the same frame. Indeed, I saw an enemy sometimes thinking my character was still there for 1 frame and try to attack it.
So, I disabled the process mode of my warped characters (
process_mode = PROCESS_MODE_DISABLED
) only to reenable it one or two frames later. Since one character has a detector Area2D, and the other has a detected PhysicsBody2D (CharacterBody2D, but other sub-types also have the issue), I'm disabling both at the same time.I noticed that when the PhysicsBody2D is inside the Area2D, the Area2D keeps registering the PhysicsBody2D forever, even after I re-enable them or move them. This can be seen when accessing both
get_overlapping_bodies
or a manual array updated in _on_body_entered and _on_body_exited via signals.Note: if you work with a CharacterBody2D and move it outside the Area while it's disabled, then re-enable it, it will be registered for 1 frame, as if its collision shape was still at the old position, then immediately unregistered. This has already been reported in #69407 and StaticBody2D doesn't have the issue, so it must be unrelated to our particular issue.
Steps to reproduce
Minimal reproduction project
v4.0.2 - PhysicsBody2D stays registered in Area2D when disabled inside.zip
EDIT: oops, forgot to remove the 3D scene
It'll be worth testing 3D too, but in this case the 3D scene has not been setup, so you can ignore it.
The text was updated successfully, but these errors were encountered: