Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We’re making changes to the Unity Runtime Fee pricing policy that we announced on September 12th. Access our latest thread for more information!
    Dismiss Notice
  3. Dismiss Notice

Feedback Time.deltaTime is not equal to Time.unscaledDeltaTime * Time.timeScale

Discussion in 'Documentation' started by twixuss_, Oct 29, 2022.

  1. twixuss_


    Nov 2, 2017
    Looking at documentation of Time.unscaledDeltaTime, you might think that Time.deltaTime is actually equal to Time.unscaledDeltaTime * Time.timeScale, but this is not true. Time.deltaTime is clamped to Time.maximumDeltaTime, but Time.unscaledDeltaTime is not clamped at all.

    So if you use Time.unscaledDeltaTime without clamping for, say, interpolation, you might get stuttering motion if your scaled frame time goes above Time.maximumDeltaTime.

    Note that by default Time.maximumDeltaTime is set to 1/3, which is most likely not going to be exceeded in any project. I stumbled upon this problem only because I changed Time.maximumDeltaTime to a pretty low value.

    This is how you clamp Time.unscaledDeltaTime:
    Code (CSharp):
    1. var clampedUnscaledDeltaTime = Time.unscaledDeltaTime;
    2. if (Time.timeScale != 0)
    3.     clampedUnscaledDeltaTime = Mathf.Min(clampedUnscaledDeltaTime, Time.maximumDeltaTime / Time.timeScale);
    In the end I'd like to see Time.maximumDeltaTime mentioned in both delta time pages.
    Because if it's not, someone might spend a bit more time debugging, like me :)
  2. MelvMay


    Unity Technologies

    May 24, 2013
    The correct place to make documentation feedback is in the Documentation forum.

    I'll move your post there.