Remove Jolt Physics project setting "Areas Detect Static Bodies" #105746
+20
−24
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As talked about in the recent update of Jolt Physics (#104449) and originally discussed in jrouwe/JoltPhysics#1476, this PR removes the project setting
physics/jolt_physics_3d/simulation/areas_detect_static_bodies
, effectively making it permanentlytrue
, in favor of leveraging the newly introducedJPH::PhysicsSystem::SetSimCollideBodyVsBody
functionality, and theJPH::CollideShapeVsShapePerLeaf
helper function, which lets us configure the amount of contacts that are cached by Jolt as part of the collision detection that it does during simulation.Warning
This is technically a breaking change, and potentially quite pervasive, depending on the project, since areas that were maybe not meant to detect static bodies now will. This does however bring Jolt Physics in line with how Godot Physics behaves (although it has its own issues with areas and static bodies) so I feel there's reasonable justification for just removing this setting completely rather than just changing its default to
true
and allowing people to disable it, especially when considering the current experimental label of the Jolt Physics integration.This project setting has become a fairly popular one to enable over the years, largely due to Godot Physics supporting this already, and despite efforts to warn people about its ill effects in Jolt Physics specifically, most seem to just go ahead and enable it anyway, since the alternatives/workarounds can be inconvenient and/or unintuitive.
As such, this removes a fairly significant performance footgun, since by default Jolt would otherwise (when enabling this project setting) generate contacts for every overlapping triangle when an
Area3D
overlaps with aConcavePolygonShape3D
, which when dealing with complex collision meshes (or many/largeArea3D
) can end up being a lot. These contacts can add a lot of overhead both in terms of CPU and memory during the simulation step in ways that might not be easy to correlate to the source of the problem.This new way of doing it is essentially exploiting the fact that
Area3D
in Godot doesn't actually expose the exact contacts between itself and the thing it's overlapping. This means that the underlying collision detection during simulation really only needs exactly one contact per shape, and that contact can be anywhere, which means we can set Jolt's underlying collision collector to be the much cheaperJPH::AnyHitCollisionCollector
for any collision involving sensors/areas.I still need to do some profiling to see the exact gains (and potential losses) from this, but this should hopefully be relatively safe merge, apart from the breaking change.
Note however that since we're now forced to always allow interactions between the broadphase layers belonging to areas and static bodies, this will presumably add some amount of additional cost to
Area3D
's collision detection, for anyone who wasn't previously relying on this project setting, but it is what it is. Being diligent about using collision masks and layers properly (which should be done anyway) should hopefully mitigate some of that.CC: @jrouwe