In this lesson, you will learn how the Unity physics engine processes the pipeline of fixed updates, collision detection, and solver iterations to keep your game simulation stable.
The Physics Clock
While your game’s visual frame rate might fluctuate depending on the hardware, the physics simulation needs a steady heartbeat to stay accurate. This is why Unity uses the FixedUpdate cycle. The physics engine doesn't run every time a frame is rendered; instead, it runs at a fixed time interval defined in your Project Settings (defaulting to 0.02 seconds).
The Three-Step Pipeline
When the physics engine wakes up for a FixedUpdate tick, it moves through three critical phases:
- Simulation Step (Integration): The engine calculates the new positions and rotations for all active
Rigidbodycomponents based on their current velocity and applied forces. - Collision Detection: Once the objects are moved to their theoretical new positions, the engine checks for overlaps. It determines if any colliders are intersecting or touching.
- Solver Iterations: This is the most crucial part for stability. Because objects might have collided in ways that create complex forces (like a stack of crates), the engine runs "solver iterations." It calculates the impulses needed to resolve these collisions, effectively "nudging" the objects so they don't pass through each other or jitter.
Why This Matters
If your objects are jittering or falling through floors, it is often because the physics engine is struggling to resolve the math within the allotted time. You can visualize this loop in your code:
void FixedUpdate()
{
// The physics engine triggers this at a constant rate
// followed immediately by the collision and solver phases.
Debug.Log("Physics tick processing at: " + Time.fixedTime);
}
If your game logic performs too much heavy work inside FixedUpdate, it can cause the simulation to fall behind, leading to "physics lag" where objects behave unpredictably. Keeping your physics-based logic concise ensures the engine has enough headroom to complete its solver iterations, resulting in a predictable and solid simulation.
Key Takeaway: The Unity physics pipeline ensures stability by decoupling simulation from frame rate, using a constant time step to calculate movement, detect collisions, and iterate through solutions for object interaction.