Inconsistent physics behavior when loading a scene

Godot Version

4.5 dev5

Question

While implementing a SceneManager loading system, I ran in to an issue related to delayed position updating using AnimatableBody3D.

My game has a save and load system that should support saving positions of nodes. The initial saved state is illustrated here:

During the ready sequence of the game, I move Obstacle (AnimatableBody3D) to Location B and Player (CharacterBody3D) to Location A on the same frame. Ideally, this would not result in a collision, but there seems to be about a 50% chance that this sequence results in the player being pushed out of Location A.

I suspect this to be because transform updates are delayed by a frame. However, what I don’t understand is the inconsistent behavior, and the fact that switching the type of Obstacle to StaticBody3D fixes the issue. How do I move these physics objects in ready without causing a collision?

Download the project from GitHub - Snowlith/physics-test

I fixed the issue.

func fix(node: CollisionObject2D):
	PhysicsServer2D.body_set_mode(node.get_rid(), PhysicsServer2D.BODY_MODE_STATIC)
	node.force_update_transform()
	PhysicsServer2D.body_set_mode(node.get_rid(), PhysicsServer2D.BODY_MODE_KINEMATIC)

By calling this method after setting positions, they move instantly.
Found the fix from this PR: force_update_transform() doesn't work for CharacterBody2D and AnimatableBody2D · Issue #76256 · godotengine/godot · GitHub