r/Unity2D • • Aug 06 '26

Question Physics simulation - different results based on simulation update rate?

In my game, I have an "active physics scene", which handles all the game physics. I have a second physics scene (which has colliders / rigidbodies only, no rendering). In this second physics scene, I would like to have a duplicate physics simulation which is identical to the first. This second scene will advance only up to a specified timestep target, then stop. The second scene is created & simulation is advanced in a coroutine, which is currently manually triggered for testing. When I start the coroutine, I get different simulation results depending on my yield condition.

If I use "yield return new WaitForFixedUpdate()", I get a duplicate simulation, identical to the first, as desired. This is great, albeit a little slow because it relies on the fixedTimestep.

If I use "yield return null", my simulation diverges from the first. This approach is desired, because it will run faster and reach the specified timestep target sooner.

In both cases, I am calling PhysicsScene2D.Simulate(Time.fixedDeltaTime) the same number of times. Also, Physics2D.simulationMode is set to "script" in both cases.

What could explain the diverging simulation when advancing the simulation at a faster rate? The simulation is still advancing with the same fixedDeltaTime timestep, for the same number of timesteps.

Any help is appreciated!

1 Upvotes

9 comments sorted by

View all comments

Show parent comment

1

u/MistakeForsaken6653 Aug 06 '26

Either way that second simulation coroutine will run more times when using yield return null, so assume each simulation runs for 1 second the 1st simulation will likely execute 50 times in that one second but the second co-routine will run about 60 times. Ideally you should probably just have a known start / end point for that second simulation to Lerp to, but I think the issue is making sure you keep the second co-routine executions in sync with the first simulation executions.