get_gravity
yields different results from _process
and _physics_process
#87996
Labels
get_gravity
yields different results from _process
and _physics_process
#87996
Tested versions
Reproducible in: Godot 4.3.dev [d335281]
System information
Windows 10 (10.0.22631)
Issue description
Related to #84640.
Due to the current implementation of
PhysicsBody*D.get_gravity
relying onbody_get_direct_state
you will end up with desync between the gravity reported by_physics_process
and the gravity reported by_process
, within the same physics frame.This means that when a body enters/exits an area with some type of gravity override,
_process
will pick up on the change before_physics_process
does, while they still report the same position in the world, which can potentially lead to subtle and hard-to-track-down bugs.The reason for this is because of how a frame is laid out in Godot, which in very simplified terms goes something like this:
_physics_process
_process
The important thing to note here is that the physics simulation/server is stepped inbetween
_physics_process
and_process
, which means that the physics simulation/server is always one tick ahead of_physics_process
while_process
is running.This means that if you use something like
body_get_direct_state
, which as the name would suggest gives you direct access to the physics server, you will bypass the state synchronization that typically happens before_physics_process
and access the most current (future) value in the physics simulation/server instead, leading to a desync with_physics_process
.Steps to reproduce
CharacterBody3D
enters theArea3D
CharacterBody3D
exits theArea3D
Minimal reproduction project (MRP)
GravityDesync.zip
The text was updated successfully, but these errors were encountered: