Time.timeScale = 0; freezes my game for a few seconds.

Hello community,

I recently implemented a pause menu, and obviously, has a Time.timeScale = 0 function to pause it, and = 1 to play it again, but a strange behaviour is happening on the first pause, it happens that in the first time i pause, everything pause and works just fine, but when i resume my game and set my Time.timeScale = 1 again, my unity freezes for 3 ou 4 seconds before it unpauses the game, just for the first time, the other times works fine, so this behaviour is pretty strange, i don’t know how to fix it.

And my script is pretty simple, just a regular:

if(pause) {
   Time.timeScale = 0;
} else {
   Time.timeScale = 1;

Anyone knows how to fix this annoying problem?
Thank you very much.

This might be a bug. Try submitting it to Unity’s bug catchers. For a quick fix, just pause at the very start of the game.

Set the default timescale to 0 and have this in one of your scripts.

void Start()
Time.timeScale = 1;