get_contact_count
yields different results from _process
and _physics_process
#88018
Labels
Milestone
Tested versions
Reproducible in: 4.3.dev [d335281]
System information
Windows 11 (10.0.22631)
Issue description
This is essentially the same problem as #87996, but for a different method.
Due to the current implementation of
RigidBody*D.get_contact_count
relying onbody_get_direct_state
you will end up with desync between the contact count reported by_physics_process
and the contact count reported by_process
, within the same physics frame.This means that when a
RigidBody*D
makes contact with something,_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
Minimal reproduction project (MRP)
ContactCountDesync.zip
The text was updated successfully, but these errors were encountered: