Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Bug 9-13 FixedUpdates per frame

Discussion in 'Editor & General Support' started by RobinHut3, Sep 17, 2023.

  1. RobinHut3

    RobinHut3

    Joined:
    Apr 6, 2022
    Posts:
    6
    I have a problem where at some frames, about every 5s my FixedUpdate is called 9 or even 13 times in one frame, and I dont even have low framrate or anything. It just randomly calls it 9 times, which of course results in a lag but there is nothing else that causes a lag. In deep profiling mode with a lot of stuff turned of my game takes 5ms per frame but with this it spikes up to 11ms which causes a bad lag. Its really weird because this only happens when my Player is moving on my procededural generated Terrain. Yesterday I changed a calculation of a fallofmap with an array of the size 20000x20000 to use UnityEnige.mathemtics "half" instead of "float" so my memory would be better but apperently this somehow leads to this bug. I though certaily this couldt have caused this FixedUpdate bug but appently it did. Any thoughts on this and why this could happen and how this might be fixable?
     

    Attached Files:

  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,701
    FixedUpdate is not driven by physics, physics is not in control of it. It's a standard call by the Playerloop. It calls the scripts, animation, physics etc.

    I'll move your post to the correct forum.
     
  3. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,948
    Check the frame immediately before this happens. if you have an unrelated slow frame before this one, it will cause FixedUpdate to have to run many times to catch up. It's possible your switch from float to half incurred a significant performance penalty.
     
    Last edited: Sep 18, 2023
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,426
    Are you computing 400 MILLION things every frame?

    Or is that just on one frame?

    If it's just one frame, then as Praetor notes it will choke up the framerate for a moment, give you a bunch of dupe catchup calls.
     
  5. RobinHut3

    RobinHut3

    Joined:
    Apr 6, 2022
    Posts:
    6
    Its just calcultated on one frame on Awake. So it only happens on start up. The thing I changed is replace all "float" with "half" and that apperently caused this. And I dont think its has anything to do with catchup, because these 12 FixedUpdate calls happen constaly also way after I run the script and only happen like every 5s because this behaviour woudnt make sense then right?, so I cant imagine that this is catchup though it might be possible that its causes some bug so that the FixedUpdate thinks it needs to catch up.

    But I think you were right about the performence. My game took way longer to start, probalby because of the half, but why would half be slower shouldt it be just as fast? Or is it some Compiler issue where it cant optimise stuff because it doesnt know half?