0
\$\begingroup\$

I want my Unity game to start with Time.timeScale = 0f becuase it starts with a main menu that is in the same scene as the game. I tried to put Time.timeScale = 0f in Awake() but that did not work as expected. Putting it in Awake() paused it almost immediately but somehow the update funtions run at least once because some objects moved a little before the game paused. How do I pause it immediately when the game starts?

\$\endgroup\$
3
  • \$\begingroup\$ As a side note it may be nicer to have the game running idle animations in the background instead of being completely paused. Keeping the screen moving is a key part of user engagement. \$\endgroup\$ Feb 10 '20 at 13:03
  • 1
    \$\begingroup\$ Thanks for the feedback, but I have already thought about that. I have animations playing anyway by setting the animators update mode to unscaled time. \$\endgroup\$
    – christian
    Feb 10 '20 at 13:21
  • \$\begingroup\$ Also check your Script execution order. Edit->project settings->script execution order. Make sure your code is being called first. Setting timeScale to 0f, is the correct way. \$\endgroup\$ Feb 10 '20 at 13:49
1
\$\begingroup\$

You can specify the setting on launch using the Time section of the project settings (Edit>Project Settings>Time).

https://docs.unity3d.com/Manual/class-TimeManager.html

\$\endgroup\$
-1
\$\begingroup\$

Note that Update function is not affected by timeScale (Though it affects all measured delta times in the Time class, except for fixedDeltaTime). So, you should build some logic to tackle this. On the start of the Update body, add if (Time.timeScale == 0f) return;. This will effectively prevent Update from running while Time.timeScale is 0.

More info on Time.timeScale from the docs.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.