Pausing a game without settiing timescale to 0

My game uses a lot of physics, animation and coroutines, so the only way I have been able to figure out to pause it while the user is in a menu is to set timescale = 0. Unfortuantely this takes away my ability to use coroutines or animations for GUI effects.

As far as I can tell, if I want timed things happening in the GUI, I’m going to have to work based on the system clock, which is going to be a bit rough. Does anybody know of a nicer way to go about all this?

Instead of using 0 for the time scale, use something like .000001, and multiply any relevant Time.deltaTime calculations by Time.timeScale.

–Eric

Brilliant! Thanks.

I have some problems with this.

I set Time.timeScale = 0.000001;

and after that i make something like this

Invoke(“continue”, 25 * Time.deltaTime);

The problem is that the script invokes the method not always at the same time. Its kind of random.

Just set the time scale to 0 and use Time.realtimeSinceStartup (instead of Time.time) for animations and coroutines that should run during pause state.

That’s because you are using Time.deltaTime in your Invoke. You normally provide invoke with the amount of seconds it has to wait before calling the function. You multiply that number with the time that the last frame happened to take, which will be different every time.

Simply remove Time.deltaTime, and probably also make 25 a lot smaller number.

OK I just created an ID to congratulate you on this very simple but very smart solution. I was breaking my head with LeanTween as all animations would take about 2 seconds to pause the game (critical for a pause menu) so did your scale thing, set the scale to ms, and the LeanTween animation instead of 2 seconds, takes 200f. Worked like a charm!

Thanks a lot good sir!!

It’s not really a great solution. I’d imagine it would introduce some floating point precision problems. The better solution is to use e.g. WaitForSecondsRealtime in the coroutine. Not sure if/how that translates to any particular Tweening library, but I’d guess they provide options for using “realtime” or “unscaled time”.