Search Unity

Question What does a beginner need to know about FixedUpdate()?

Discussion in 'Editor & General Support' started by IIBearWithII, May 28, 2023.

  1. IIBearWithII

    IIBearWithII

    Joined:
    Feb 15, 2023
    Posts:
    87
    I'm thinking of pausing a game I'm making, but don't want to actually apply the pause until the VERY beginning of the next frame (assuming Awake, OnEnable, Reset, and Start have all done their thing). Would FixedUpdate() be appropriate?


    Also, in the manual on "order of execution for event functions" it says that FixedUpdate() is for User Callback. I assume that means it's a function for me to use, and not something the computer itself uses automatically. Is that correct?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    IIBearWithII likes this.
  3. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,935
    FixedUpdate is just to use for physics.
     
    IIBearWithII likes this.
  4. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,445
    I can't see many ways that you would need to worry about setting the flag in the middle of a frame, but if it's a real concern, you can start a coroutine which uses WaitForEndOfFrame to achieve the necessary "between frames" flip of your state. It basically lets you run your own code at the moment that the frame has fully been rendered but before the user sees it, to allow for screen grabbing or other things that can't affect the current update loop because it's already done.

    The Execution Order chart Kurt gave you shows that moment in the flow.
     
    IIBearWithII likes this.
  5. IIBearWithII

    IIBearWithII

    Joined:
    Feb 15, 2023
    Posts:
    87
    Thanks for the info. WaitForEndOfFrame sounds like another good option!