Playing animation with Time.timeScale = 0

Lately, our team faced issue with time scale and animation. We are using Time.timeScale = 0 for pausing our physic based game. But in pause menu we need button animations to play idle and random scale up animation. So we did small research and decided to share with you.

Factors affected by Time.timeScale

  1. Physics simulations. FixedUpdate - FixedUpdate functions will not be called when timeScale is set to zero.
  2. Coroutines - Setting timeScale to 0 doesn't stop coroutines, but stops WaitForSeconds. Coroutines continue executing each frame, but WaitForSeconds apparently uses the current Time.deltaTime, which becomes zero when timeScale = 0.
  3. Invokes and InvokeRepeating
  4. Particle System
  5. Animations. But if we will use Animator, we can make animation to ignore the Time.timeScale parameter.  All we need to do, is to set Update Mode to Unscaled Time, as showed on the image bellow


Factors not affected by Time.timeScale

1. Update - Time.timeScale will not make any affect on Update call, it will invoked as per the frame rate until and unless it is not used in any statement for computation. But  Time.deltaTime will be 0. so movment implemented as showed bellow will not work:

function Update () {
    // Move the object 10 meters per second!
    var translation : float = Time.deltaTime * 10;
    transform.Translate (0, 0, translation);

 2. OnGUI - OnGUI and its event have overlaying architecture over Time.timeScale, so it won't be affected if it goes to lower or set to 0.


So here is how we solved out  issue with pause menu animation. 

First of all make animation ignore the Time.timeScale parameter, was easy enough.  All we need to do, is to use Animator and set Update Mode to Unscaled Time, as showed on the image bellow:



Used sourses:



User replies

No replies yet