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. Dismiss Notice

Question fixed update vs update

Discussion in 'Scripting' started by puddleglum, Jul 30, 2023.

  1. puddleglum

    puddleglum

    Joined:
    May 11, 2020
    Posts:
    380
    if i need to run a check very fast and often but didn't need it to happen every single frame, would it be more performance efficient to run it in fixed update or in update
     
  2. RadRedPanda

    RadRedPanda

    Joined:
    May 9, 2018
    Posts:
    1,593
    FixedUpdate does not actually happen at a separate time than Update, it just runs right before every Update the amount of times for the Physics to catch up. I don't believe it would really be a performance hit either way, but I imagine if you didn't use any physics at all you could cut out those step calculations.
     
    Ryiah likes this.
  3. puddleglum

    puddleglum

    Joined:
    May 11, 2020
    Posts:
    380
    oh i thought fixed update happened a fixed amount every second. but yeah i agree it shouldn't be a performance hit either way
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,754
    Ryiah likes this.
  5. zulo3d

    zulo3d

    Joined:
    Feb 18, 2023
    Posts:
    547
    It does.. RedPanda is just saying that... err.. hmm... He's just saying things! Don't ask questions!..
     
  6. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,135
    Under ideal conditions where the target device is able to keep up it will happen a fixed amount per second. It's just not guaranteed when it will happen during that second. If the target device can't keep up all of that gets thrown out the window and that's what the links @Kurt-Dekker gave touch on.
     
  7. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    5,883
    It doesn't happen at strictly fixed intervals. It plays catch up with Update using an accumulator. It's only there for the physics engine and not a way to have something happening at regular intervals.

    A regular timer in Update will be more reliable.
     
    puddleglum, Ryiah and Sluggy like this.
  8. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,002
    Yup FixedUpdate doesn't really run at fixed intervals, just the end result looks like it does.
     
    Unifikation likes this.
  9. Unifikation

    Unifikation

    Joined:
    Jan 4, 2023
    Posts:
    1,045
    Best way to do this is create your own thread and timer upon/within it.

    Anything else will suck time out of the precious main thread that just about everything in Unity relies upon.
     
    puddleglum likes this.
  10. puddleglum

    puddleglum

    Joined:
    May 11, 2020
    Posts:
    380