Skip to content

Remove force enter/exit logic from JoltArea3D #106693

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

Merged
merged 1 commit into from
May 28, 2025

Conversation

mihe
Copy link
Contributor

@mihe mihe commented May 21, 2025

Prior to merging #106490 we were unable to rely on Jolt's contact listener to emit the relevant events whenever an overlapping body/area would enter/exit as a result of disabling the Area3D.monitoring property, since it had no actual impact on the underlying collision detection. This led to having a bunch of messy bookkeeping code in JoltArea3D that would essentially just simulate those events as you toggled said property.

Now with #106490 merged we can finally remove all that, in favor of just relying on Jolt's contact listener events, greatly simplifying things.

There was also a minor related bug lurking in JoltArea3D::_space_changing, from #100983, which is that we were queueing up a bunch of exit events (one per shape pair) as part of force-exiting all the overlapping bodies/areas, as the Area3D was leaving/changing the physics space. Then we would immediately remove that same Area3D from the list of areas that were meant to flush their events next tick, since its corresponding scene node would be gone by then anyway. This meant that if you never actually freed that area (e.g. when just pulling it out of the scene tree temporarily) you would be sitting on some amount of allocated memory (i.e. the pending events) for no reason whatsoever.

Now instead we just clear the entire bodies_by_id and areas_by_id maps, which hold all the overlaps and any pending events they might have, as we leave/change the physics space.

@mihe mihe added this to the 4.x milestone May 21, 2025
@mihe mihe requested a review from a team as a code owner May 21, 2025 20:25
@Repiteo Repiteo merged commit dcde70f into godotengine:master May 28, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented May 28, 2025

Thanks!

@mihe mihe deleted the jolt/area-cleanup branch May 28, 2025 18:06
@soloparatolos
Copy link

I'm working on a game with a "relatively" fast moving CharacterBody3d and was not getting the areas to detect the body entering consistently (with jolt). I'll take a look with this PR and open an issue if the problem persist. Thanks for your work @mihe

@mihe
Copy link
Contributor Author

mihe commented May 29, 2025

I'm working on a game with a "relatively" fast moving CharacterBody3d and was not getting the areas to detect the body entering consistently (with jolt).

@soloparatolos It shouldn't have anything to do with this PR.

Neither areas nor CharacterBody3D, in both Jolt and Godot Physics, have support for any sort of continuous collision detection, so if the steps of your CharacterBody3D are greater than the size of the area then you may very well step past it without it detecting any overlaps.

I believe the only real way to fix that is to increase physics/common/physics_ticks_per_second so that you take smaller steps and check for area overlaps more often.

But if there's some discrepancy between Jolt and Godot Physics then please do make an issue for it.

@soloparatolos
Copy link

My attempt was brief; just changed to jolt and tested the project. I'll test it properly and open an issue if needed, this is probably just a matter of default values. Thanks for the clarifications!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants