Under Construction
Unity••18 min•100 views••

Why does Unity run multiple physics steps after a frame spike?

Minh Khoa

Minh Khoa

Author

image.pngIf CPU Profiler reports six calls Physics.Simulate in one frame, I would check the previous frame. A frame that takes too long to load assets can make Unity run multiple catch-up physics steps in the next frame. If you only look at the total time of Physics.Simulatethe next frame can easily be optimized in the wrong place. Unity Manual — Physics performance issues

1. What does one 20 ms physics step mean?

With Time.fixedDeltaTime = 0.02each physics step advances the game world by 20 ms. CPU how long it takes to finish that step depends on the number of collisions, physics constraints, and logic running in FixedUpdate(). Unity keeps the time that is not enough for one step and carries it over to the next frame. As a result, a frame can have 0, 1, or more FixedUpdate(). Unity Manual — Fixed updates

For example, in a racing game. Frame N takes 120 ms to load a section of the track. With timeScale = 1there is no leftover time from before and the default cap, frame N+1 has six physics steps to perform. Assuming each step takes 3 ms, those six steps alone already take 18 ms, exceeding the budget 16,67 ms/frame for the 60 FPStarget. The loading task has finished in frame N, but the catch-up cost can still make frame N+1 late.

2. Lower Time.maximumDeltaTime what changes?

Keeping the 120 ms example and changing only Maximum Allowed Timestep in Project Settings.

Time.maximumDeltaTimeGame time recordedNumber of physics steps
About 333 ms, default120 ms6
60 ms, test configuration60 ms3

In the second configuration, the player still experiences the full 120 ms. Unity only lets game time advance 60 ms and does not add the difference back into Time.time in later frames. If the race timer accumulates Time.deltaTime in Update()it also only records 60 ms. This is a trade-off in gameplay time when reducing the number of catch-up steps. Unity Manual — Handling variation in time

3. Choose what to optimize

On the target device, I look at CPU Usage → Timeline to find the first frame that exceeds the budget, then look at the Calls column of Physics.Simulate in Hierarchy in the next frame.

  • Multiple steps, but the cost of each step is still normal. If the slow frame chain starts with a track-loading operation, prioritize fixing the loading operation.

  • Only one step is taking a lot of time. Check the number of physics contacts, collision callbacks, and looping logic in FixedUpdate().

  • Catch-up steps make multiple consecutive frames exceed the budget. Try reducing maximumDeltaTimemeasure frame time again, and check the systems that use game time as well, especially the lap timer. Unity API — Time.maximumDeltaTime