Search Unity

FixedUpdate called multiple times by no reason

Discussion in 'Physics' started by panzerkoblyk, Jun 21, 2017.

  1. panzerkoblyk

    panzerkoblyk

    Joined:
    May 1, 2017
    Posts:
    13
    Hi,

    Recently we've upgraded our project to Unity 5.6.1p2 from 5.4.2f2 and noticed huge performance drop on ios devices(ipad air2 60fps droped to 30fps). After some investigation I noticed that the first version where our problem reproduced is 5.4.3p1.

    In our project we're using Time.fixedDeltaTime = 0.015, Application.targetFramerate = 60, QualitySettings.vSyncCount = 1.
    I profiled project in 5.4.3f1 and 5.4.3p1 versions and got some strange results(I set screen resolution to very low and disabled all graphics effects to be sure that this is not GPU problem).

    Here is profiler screen in 5.4.3f1:

    FixedUpdate is calling 1 or 2 times.

    And profiler screen in 5.4.3p1:


    FixedUpdate is calling 2 or 3 times.

    These screenshots of same project running on Ipad Air2 but with different versions of Unity.

    I can't find anything relevant to this problem in 5.4.3p1 changelog(5.4.4 changelog too). Maybe something had changed with how FixedUpdate is calling?

    Please help, because we can't update with this problem.
     
    Last edited: Jun 21, 2017
  2. Hyblademin

    Hyblademin

    Joined:
    Oct 14, 2013
    Posts:
    725
    This is how FixedUpdate is supposed to work.

    FixedUpdate doesn't update independently from the game's framerate, it just runs the correct number of times every frame right before Update, be it 0 times or 10 times-- the number of times depends on how much time passed since the last frame. If your physics step is slightly smaller than your target frame time (0.015 vs 1/60 = 0.01667) then there will be some frames where FixedUpdate runs twice to catch up to its target, or more if there are slow frames. If a really terrible frame clocks in at 0.1 seconds, then FixedUpdate will be called 6 times in a row before the next Update.

    I know this doesn't answer your question of why your game's performance has declined, but it helps to know that this normal behavior. Let me know if I'm misunderstanding something.
     
    Neiist and Mattstg like this.
  3. panzerkoblyk

    panzerkoblyk

    Joined:
    May 1, 2017
    Posts:
    13
    Thank for your answer, but I know that FixedUpdate depend on framerate :)

    I can't understand what changed between versions and why instead of 1 and rarely 2 calls we get 2 and rarely 3 FixedUpdate calls.
     
  4. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,510
    Update and FixedUpdate may be considered two separate execution paths.
    • Update is called as much as possible based on VSync settings. Update frames may be skipped if necessary. Time.deltaTime is a variable value here.
    • FixedUpdate is called at the physics update rate given by Project Settings > Time > Fixed Timestep. No FixedUpdate frames will be ever skipped. Time.deltaTime here is always the fixed timestep.
    There may be several Update calls between each FixedUpdate call. This is the most common scenario: Update runs at the maximum frame rate allowed by the hardware, and the FixedUpdate calls are interleaved between them at the proper rate.

    But there may be many FixedUpdate calls between each Update call as well. This is typically an issue: the game is too intensive for the hardware so there are massive frame skips at Update. At the same time the physics must run at a constant rate without skipping any frame, so many FixedUpdate calls will occur until the hardware has a chance to issue the next Update cycle.
     
  5. panzerkoblyk

    panzerkoblyk

    Joined:
    May 1, 2017
    Posts:
    13
    Edy, Thanks for your answer!

    Maybe I asked my question not very clear. My problem is not an understanding how FixedUpdate and Update works, but why two sequenced versions of Unity produce such different results.

    We have a project with physics and some network stuff:


    In 5.4.3f1 all works great. In 5.4.3p1(first patch for this version) and later - not. I want to discover why, because changelog and my tests give me no answers.
     
    bombsquare likes this.
  6. sed

    sed

    Joined:
    Feb 13, 2013
    Posts:
    5
    Have you found out what happened?