Fix transform updates sometimes being discarded when using Jolt

Co-authored-by: Jorrit Rouwe <jrouwe@gmail.com>
(cherry picked from commit e7cf2f42cc71179cb7e4d7caa35f3d3a9834dc66)
This commit is contained in:
Mikael Hermansson
2026-01-25 16:36:19 +01:00
committed by Thaddeus Crews
parent 19df5470c8
commit aff6e91048

View File

@@ -126,7 +126,6 @@ JoltSpace3D::JoltSpace3D(JPH::JobSystem *p_job_system) :
physics_system->SetGravity(JPH::Vec3::sZero()); physics_system->SetGravity(JPH::Vec3::sZero());
physics_system->SetContactListener(contact_listener); physics_system->SetContactListener(contact_listener);
physics_system->SetSoftBodyContactListener(contact_listener); physics_system->SetSoftBodyContactListener(contact_listener);
physics_system->SetBodyActivationListener(body_activation_listener);
physics_system->SetSimCollideBodyVsBody([](const JPH::Body &p_body1, const JPH::Body &p_body2, JPH::Mat44Arg p_transform_com1, JPH::Mat44Arg p_transform_com2, JPH::CollideShapeSettings &p_collide_shape_settings, JPH::CollideShapeCollector &p_collector, const JPH::ShapeFilter &p_shape_filter) { physics_system->SetSimCollideBodyVsBody([](const JPH::Body &p_body1, const JPH::Body &p_body2, JPH::Mat44Arg p_transform_com1, JPH::Mat44Arg p_transform_com2, JPH::CollideShapeSettings &p_collide_shape_settings, JPH::CollideShapeCollector &p_collector, const JPH::ShapeFilter &p_shape_filter) {
if (p_body1.IsSensor() || p_body2.IsSensor()) { if (p_body1.IsSensor() || p_body2.IsSensor()) {
@@ -187,6 +186,8 @@ void JoltSpace3D::step(float p_step) {
_pre_step(p_step); _pre_step(p_step);
physics_system->SetBodyActivationListener(body_activation_listener);
const JPH::EPhysicsUpdateError update_error = physics_system->Update(p_step, 1, temp_allocator, job_system); const JPH::EPhysicsUpdateError update_error = physics_system->Update(p_step, 1, temp_allocator, job_system);
if ((update_error & JPH::EPhysicsUpdateError::ManifoldCacheFull) != JPH::EPhysicsUpdateError::None) { if ((update_error & JPH::EPhysicsUpdateError::ManifoldCacheFull) != JPH::EPhysicsUpdateError::None) {
@@ -210,6 +211,9 @@ void JoltSpace3D::step(float p_step) {
JoltProjectSettings::max_contact_constraints)); JoltProjectSettings::max_contact_constraints));
} }
// We only want a listener during the step, as it will otherwise be called when pending bodies are flushed, which causes issues (e.g. GH-115322).
physics_system->SetBodyActivationListener(nullptr);
_post_step(p_step); _post_step(p_step);
stepping = false; stepping = false;