Search Unity

FixedUpdate skip some miliseconds?

Discussion in 'Physics' started by augustinus, Mar 10, 2017.

  1. augustinus

    augustinus

    Joined:
    Feb 3, 2015
    Posts:
    25
    I know FixedUpdate called before Update call. And it repeat it's fixed update loop during frame time.

    But, what if we are in this case.

    Time.fixedDeltaTime is 0.02, So FixedUpdate is called at every 0.02 seconds.
    The frame time, Time.deltaTime is 0.03.

    So, FixedUpdate is called just once, because frame time is less than 0.04.
    Then, where is the remained time 0.01 seconds?
    Unity engine just skip this time? Or keep it and use in next frame?
     
    Last edited: Mar 10, 2017
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    If you set fixedDeltaTime to .02, then Unity attempts to run physics 50 times per second, the key word being "attempts". Other than that you can't rely on it being called on an exact schedule; FixedUpdate may not be called at all for any given rendering frame, or it might be called more than once. If the CPU is stressed too much then Unity will slow everything down, based on the maximum allowed timestep setting in the time manager.

    --Eric
     
  3. dadude123

    dadude123

    Joined:
    Feb 26, 2014
    Posts:
    789
    Hmm, interesting.
    Eric, if I'd have fixedDeltaTime set to 0.05 (so 50ms) and I'd let unity run for 1 hour, it should have called FixedUpdate 3600000 times, right?

    Or could it have been a little more/less because of rounding errors?
    Or in other words: can you actually rely on the timing (assuming no major lag sources)?
    If Unity shaves off a tenth of a millisecond here and there, then you can't really rely on the timing, can you?

    I mean if you'd add all the Time.deltaTime in Update() over an hour, would you actually get to an hour, or less because of rounding errors.

    If there are rounding errors you can't really rely on Time.time for network stuff either, or how does that work then?
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    No, you can't rely on a 100% exact number of FixedUpdate calls in a given timeframe.

    --Eric