Search Unity

time.unscaledDeltaTime begin with high number

Discussion in 'Scripting' started by halevi, Sep 17, 2021.

  1. halevi

    halevi

    Joined:
    Dec 13, 2020
    Posts:
    35
    when i write debug to display time.unscale delta time (i write it in update) in the first frame the value is very
    high , why its so high in the first frame? its bug or im missing something?
     

    Attached Files:

  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,689
    First frame is always iffy: could be loading, CPU caching, graphics stall, OS process fiddling, could be anything.

    ALL of my games have a single-frame black-background scene called
    zeroscene.unity
    with a single script called
    zeroscene.cs
    and all it does is go to the next scene.
     
    Last edited: Sep 17, 2021
    halevi likes this.
  3. FernandoHC

    FernandoHC

    Joined:
    Feb 6, 2018
    Posts:
    338
    The first frame of the scene play? Yeah it should be considerably slower than other frames with less things to process. delta time, is the time it takes between logical frames in unity. So it seems normal and not a bug.
     
  4. halevi

    halevi

    Joined:
    Dec 13, 2020
    Posts:
    35
    ok so ןim curious why its not happend with when i write debug of time.delta time?(its show me usually 0.02 in the first frame its very small change from the next frames but with unsceled its show me in the first frame numbes like 3f,4f atc very different from the next frames )time.delta time in the first frame not affected from proceed things like time.unsceled delta time?
     
    Last edited: Sep 17, 2021
  5. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,531
    Because Time.deltatime and Time.time are scaled. Unity adjusts that time data for simulation.

    Time.unscaledTime and Time.unscaledDeltaTime.

    What's likely happening is unity doesn't use a timescale between Awake and the first Update call to avoid those sorts of things.

    If it's a problem come up with a way to ignore it on the first frame like @Kurt-Dekker suggested.
     
    halevi likes this.
  6. halevi

    halevi

    Joined:
    Dec 13, 2020
    Posts:
    35
    ok intersting i think figure out what heppend the calculation of the first frame with time.unscaled time happned from the moment when i prees play becouse its not scaled till the game actually running when time delta like you say unity adjust the data time and the calculation of the first update begin only when the game actually running
     
  7. Cameron_SM

    Cameron_SM

    Joined:
    Jun 1, 2009
    Posts:
    915
    Weird. Perhaps the baselines for all Unscaled Time and RealTimeSinceStartup are measured in a different place? Unscaled is done statically and happens before scene load maybe? Either way, I'd call that a bug,

    Submit a bug report with minimal repo case. The two values really ought to be comparable from frame 1 if game time isn't being scaled. There's no limit to how large Time.deltaTime can be and they should all be measured from the same baselines.
     
    halevi likes this.