Repository: godotengine/godot (language: cpp)

Issue:
Jolt Physics and sync_to_physics prevents any AnimatableBody3D transforms
### Tested versions

- Reproducible: 4.4.beta1
- Not reproducible: 4.4.dev7

### System information

Godot v4.4.beta1 - Windows 10 (build 19045) - Multi-window, 2 monitors - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1070 (NVIDIA; 32.0.15.6094) - AMD Ryzen 5 3600 6-Core Processor (12 threads)

### Issue description

Using the Jolt physics engine and enabling `AnimatableBody3D.sync_to_physics` stops the object from moving at all when setting a transform, position or similar.

Disabling `sync_to_physics`, or switching to the Godot physics engine fixes the problem.

 

### Steps to reproduce

Create an `AnimatableBody3D` Node. Set `sync_to_physics` to true. Use the Jolt physics engine.

### Minimal reproduction project (MRP)

[jolt-transform-bug.zip](https://github.com/user-attachments/files/18464415/jolt-transform-bug.zip)



Discussion / hints:
I guess https://github.com/godotengine/godot/pull/100056 now depends on this 
This looks to be yet another regression caused by #100983.

Fix patch:
diff --git a/modules/jolt_physics/objects/jolt_body_3d.cpp b/modules/jolt_physics/objects/jolt_body_3d.cpp
index d1a40e7b105c..ac2b37470ef1 100644
--- a/modules/jolt_physics/objects/jolt_body_3d.cpp
+++ b/modules/jolt_physics/objects/jolt_body_3d.cpp
@@ -210,20 +210,6 @@ void JoltBody3D::_move_kinematic(float p_step, JPH::Body &p_jolt_body) {
 	p_jolt_body.MoveKinematic(new_position, new_rotation, p_step);
 }
 
-void JoltBody3D::_pre_step_rigid(float p_step, JPH::Body &p_jolt_body) {
-	_integrate_forces(p_step, p_jolt_body);
-	_enqueue_call_queries();
-}
-
-void JoltBody3D::_pre_step_kinematic(float p_step, JPH::Body &p_jolt_body) {
-	_update_gravity(p_jolt_body);
-	_move_kinematic(p_step, p_jolt_body);
-
-	if (reports_contacts()) {
-		_enqueue_call_queries();
-	}
-}
-
 JPH::EAllowedDOFs JoltBody3D::_calculate_allowed_dofs() const {
 	if (is_static()) {
 		return JPH::EAllowedDOFs::All;
@@ -1237,13 +1223,18 @@ void JoltBody3D::pre_step(float p_step, JPH::Body &p_jolt_body) {
 		} break;
 		case PhysicsServer3D::BODY_MODE_RIGID:
 		case PhysicsServer3D::BODY_MODE_RIGID_LINEAR: {
-			_pre_step_rigid(p_step, p_jolt_body);
+			_integrate_forces(p_step, p_jolt_body);
 		} break;
 		case PhysicsServer3D::BODY_MODE_KINEMATIC: {
-			_pre_step_kinematic(p_step, p_jolt_body);
+			_update_gravity(p_jolt_body);
+			_move_kinematic(p_step, p_jolt_body);
 		} break;
 	}
 
+	if (_should_call_queries()) {
+		_enqueue_call_queries();
+	}
+
 	contact_count = 0;
 }
 
diff --git a/modules/jolt_physics/objects/jolt_body_3d.h b/modules/jolt_physics/objects/jolt_body_3d.h
index 4f5d4006edcf..9b9472e73ae8 100644
--- a/modules/jolt_physics/objects/jolt_body_3d.h
+++ b/modules/jolt_physics/objects/jolt_body_3d.h
@@ -110,6 +110,7 @@ class JoltBody3D final : public JoltShapedObject3D {
 
 	virtual void _add_to_space() override;
 
+	bool _should_call_queries() const { return state_sync_callback.is_valid() || custom_integration_callback.is_valid(); }
 	void _enqueue_call_queries();
 	void _dequeue_call_queries();
 
@@ -117,9 +118,6 @@ class JoltBody3D final : public JoltShapedObject3D {
 
 	void _move_kinematic(float p_step, JPH::Body &p_jolt_body);
 
-	void _pre_step_rigid(float p_step, JPH::Body &p_jolt_body);
-	void _pre_step_kinematic(float p_step, JPH::Body &p_jolt_body);
-
 	JPH::EAllowedDOFs _calculate_allowed_dofs() const;
 
 	JPH::MassProperties _calculate_mass_properties(const JPH::Shape &p_shape) const;


Test patch: