Physics2D.autoSimulation = false; is the greatest thing

I was dumb, and decided to try the newest 2017 beta, because I heard you could turn autoSimulation off. The beta editor is pretty crashy, but…

Finally we can get rid of that stupid fixedupdate nonsense! :smile:

setting Physics2D.autoSimulation = false in initialization and then calling Physics2D.Simulate(Time.deltaTime) from my updatemanager, on the normal update pulse, gets the physics and rendering completely in sync (finally!)

no more subtle jitter due to sampling simulation at uneven intervals, no more framerate deathspiral due to simming more than one frame as framerate drops. Finally we have a proper dynamic simulation!

2 Likes

You’re welcome. I’ll also update it so it can be called outside of play-mode too.

2 Likes

This change is seriously appreciated. My game runs smoother, faster, and more consistent on low end androids, for example. Thank you, Melv.

here’s a simple scene that lets you play with these things via MasterControl on the main camera.

3067864–230624–DynamicUpdate.zip (25.7 KB)

I probably should have put a background in there to really make the jitter apparent, and also should have made the camera follow one of the objects because that’s where fixed update sucks the most. however, any time you see any of those circles overlapping, that’s interpolation error…

For comparison I also should have added the hacky Update() {Time.fixedDeltaTime = Time.deltaTime;} which does better than interpolating but is still an inferior approximation of Simulate(Time.deltaTime)- inferior as it is reactive, saying “next frame, step how long we stepped this frame”- less synchronized, and often causes the simulation to run twice per render frame if you have a dip in framerate, further dipping the framerate.

Would love this so much for the 3D version as well. Please let the 3D team know!

Also, is it actually the same performance to manually tick like this assuming all things equal (ie it would cost just the same assuming fixed update was used and was at the same rate) - ie are there penalties?

Because I would love to not spread my code all over the place too!

The 3D version is there too already.

There’s no difference in performance whether you call it or we do during the fixed update.

1 Like

Another great thing about Physics2D.Simulate() is that you are no longer bound to Time.deltaTime.

Further quality improvements can be found by replacing Time.deltaTIme with a high-resolution stopwatch such as .

long ticks = stopwatch.ElapsedTicks;
stopwatch.Reset();
stopwatch.Start();
float deltaTime = Time.timeScale * ((float)ticks / System.Diagnostics.Stopwatch.Frequency);

If you graph the output of that stopwatch against Time.deltaTime, you will see that they fluctuate differently. We found the stopwatch was a decided improvement (reduced jitter) after some blind A/B tests across a variety of devices.

I have updated that project to better reflect all of this stuff… it now has a background and a camera following an object to make jitter much more visible. you can also run it in earlier unity builds by commenting out #define UNITY_2017 in the top of MasterControl.cs.

3074043–231199–DynamicUpdate.zip (25.8 KB)

With a 60fps Update and FixedUpdate, how can I simulate the physics at 240Hz?

I’m struggling with what I’m supposed to enter to make this work… as per this thread of my moronity:

https://discussions.unity.com/t/698428