Search Unity

Catrastrophic Breakage - Time.time can sometimes be reset to 0 in the middle of a game.

Discussion in 'Scripting' started by Zergling103, Aug 24, 2016.

  1. Zergling103

    Zergling103

    Joined:
    Aug 16, 2011
    Posts:
    392
    I've discovered through debugging efforts that Time.time (https://docs.unity3d.com/ScriptReference/Time-time.html) has a very strange bug.

    The expected behaviour?
    • Time.time starts at 0 when the game launches.
    • Time.time increments by some amount per frame such that it increases by 1 every second.
    • Time.time never decrements and cannot be reset unless the game executable is completely closed.
    The actual behaviour? Mostly the above, however, sometimes, Time.time will just seemingly randomly get set back to 0 in the middle of a game. That is, without closing the executable.

    Symptoms:
    • Anything that uses Time.time directly or indirectly breaks in some complex and unpredictable way.
    • Coroutines stop functioning for some period of time. (Likely the same amount of time between game start and the first symptoms.)
    • Any other execution scheduling using Time.time as timestamps are delayed similarily to Coroutines.
    • Anything using Time.time to calculate time deltas will wind up using negative deltas, IE going back in time, sometimes breaking math.
    Anyone else seeing this? What would cause this?
     
  2. lloydsummers

    lloydsummers

    Joined:
    May 17, 2013
    Posts:
    359
    Are you doing anything unusual with time scaling? Using it for pausing or reversing it with something like Chronus?

    Time.time is the time since launch, using time.scale.

    Time.realtimeSinceStartup is the time since launch, regardless of time scale.

    Maybe?