Skip to content

Instantly share code, notes, and snippets.

@unitycoder
Created January 31, 2024 11:12
Show Gist options
  • Select an option

  • Save unitycoder/be31323048ac654fa6a9158cfde1b1c9 to your computer and use it in GitHub Desktop.

Select an option

Save unitycoder/be31323048ac654fa6a9158cfde1b1c9 to your computer and use it in GitHub Desktop.
Unity Update and FixedUpdate

Update and FixedUpdate may be seen as two separate execution paths, not necessarily "after" or "before" each other.

Update

  • Executes on each visually presented frame. When you see 134 FPS in the stats it means 134 Update cycles per second.
  • Time.deltaTime is the time between one update cycle to another.
  • Updated for Unity 2020.2: If VSync is enabled then Update is called at the display's refresh rate and Time.deltaTime is the time between each frame presentation (typically 1 / refresh rate).
  • Frames may be skipped sometimes if the cpu/gpu load can't keep the display rate.

FixedUpdate

  • Executes at a fixed rate (50 Hz by default, defined in Project Settings > Time > Fixed Timestep).
  • Time.deltaTime is always the value specified in the Fixed Timestep setting.
  • FixedUpdate cycles won't be skipped ever: instead, the game time may be "slowed down" and/or Update calls will be skipped in order to perform every single FixedUpdate call.

There are situations where multiple FixedUpdate calls are performed between each Update call. Most frequently, Update is called several times between each FixedUpdate call.

Rule of thumb:

  • Update: visual stuff, camera, effects, things that may be adapted to varying delta time, and skipped for saving CPU/GPU.
  • FixedUpdate: physics, gameplay, AI, things that depend on precise timing and/or would affect gameplay if skipped.

Putting everything in FixedUpdate is incorrect. The game should be able to skip things to adapt to situations of intensive CPU/GPU usage. Otherwise, gameplay will just slow down in those cases.

LateUpdate executes in the same cycle as Update, but after all Update functions have been called.

Source

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment