Late Update in Unity

by Michael Sacco Published August 21, 2023

I was talking with one of my friends the other day. He was asking me about when he should use Update() vs. LateUpdate(). Should he just always use LateUpdate()? Or always Update()? Or manually set the Execution Order? Probably not that last option. Both Update() and LateUpdate() are useful event functions in Unity. If you understand how to use both of them, then you can build a better project. And, you can build it faster with fewer weird bugs.

What you need to know about LateUpdate

  • LateUpdate is an event function that Unity calls after it calls Update().
  • LateUpdate is great for when you need to move the Camera or other Object to track an object that changes during Update.
  • LateUpdate is called every frame.

How do I use Late Update?

Using LateUpdate is easy. Just declare the method signature in your class like you would with Update() or Start(). Here’s an example:


using UnityEngine;

public class LateUpdateExample : MonoBehaviour

{

   Transform target;

   void LateUpdate()

   {

       transform.LookAt(target);

   }

}

Understanding LateUpdate

In this article, we will review the Late Update function. Late Update is a basic update function in Unity that you will use often when making a game. You must understand how Late Update works and when to use it in order to build good games.

Understanding Unity Update Functions

Update functions in Unity are like checkpoints during gameplay where you can add your code to make things happen.

Update functions are called every frame.

Unity offers three major checkpoints that you can hook into.

  • Update(): Regular updates for general game logic stuff.
  • FixedUpdate(): Deals with how physics objects move in the game.
  • LateUpdate(): The one we’re talking about. It comes after the others and is great for adjusting things like the camera, animations, or dependent objects.

In this article, we’ll focus on LateUpdate() in order to understand how to use it.

Why are Update Functions Important in Game Development?

Update functions make it easy for you to control how the game behaves from frame-to-frame. You can depend on Unity to call every Update function on every component every single frame. This makes it easy for you to listen for player input, check for physics interactions, or track in-game actions.

Understanding Late Update in Unity

Late Update in Unity is like a helper that comes after the main work is done. It’s a special moment when you can fix things just before showing them on the screen.

A game loop is a series of tasks. The engine executes each task in order. Then, it starts again from the top.

Late Update is one of these tasks. It happens after the engine has finished most of the other tasks. It is super useful. You use it to adjust an object or component in response to a change that took place during Update or FixedUpdate.

Unity has a helpful page that goes in depth on the series of tasks that it runs through during the lifecycle of your game. This series of tasks is referred to as the Execution Order: https://docs.unity3d.com/Manual/ExecutionOrder.html

The most important event functions in Unity, in chronological order

I went ahead and documented the most crucial event functions that you need to know about. Unity executes plenty more tasks than this. But, you should start with understanding these.

* FixedUpdate may execute multiple times in one frame, depending on your game’s Physics Timestep.

When should I use Late Update?

  • If you are executing general game logic and calculations, use Update.
  • If you are dealing with camera movements or object tracking, use Late Update.

A practical use case for Late Update

Let’s set the scene for this example.

You have a box in your game. Your box moves one unit to the right every frame. You have a camera that is always looking at this box. For your box movement, you should use Update. For your camera, you should use LateUpdate.

Here’s an example of the script you might use for your box.


using UnityEngine;

public class BoxMovementExample : MonoBehaviour

{

   void Update()

   {

       transform.Translate(1f \* Time.deltaTime, 0, 0);

   }

}

Then, you need a component to look at your box. This component goes on your camera.


using UnityEngine;

public class BoxLookAtExample : MonoBehaviour

{

   Transform box;

   void LateUpdate()

   {

       transform.LookAt(box);

   }

}

Managing Update Functions Order

Timing is everything in game development, and managing the order of update functions is no exception.

Unity employs a specific sequence for calling Update, FixedUpdate, and LateUpdate functions. It is important that you understand this order and design your game around it so that your game does what you expect it to.

❌ You can’t change Unity’s default event function update order.

✅ You can prioritize functions using the Script Execution Order Settings

Managing the Script Execution Order

You can override the execution order for specific scripts within an event stage (like Update) by using Unity’s Script Execution Order options. Learn more about these options on Unity’s documentation page: https://docs.unity3d.com/Manual/class-MonoManager.html

Resources for Learning Late Update

I compiled some additional resources for LateUpdate. These resources should help you get a better understanding on how and when to use this event function.

Use LateUpdate Well

As a game developer using Unity, it is extremely important that you understand LateUpdate: How it works, when it runs, and when you should use it. By understanding these points, you will write better code and build better games.

Speaking of building better games. I create powerful and easy-to-use game assets for Unity. If you want to build an OK game, close this tab immediately. But, if you want to build the best game, I have something for you. From visual effects to realistic materials to volumetric fog, my assets will help you build a better game. If you’re not convinced, check out my collection of free and premium assets: https://occasoftware.com/assets

FAQs

Q1: Can I use LateUpdate for physics-related changes?

A1: Physics methods like BoxCast or SphereCast are available from LateUpdate. However, you should always use FixedUpdate for physics-related code and changes in order to write rock-solid, predictable games.

Q2: Is LateUpdate exclusive to camera adjustments?

A2: No, LateUpdate can be used for various tasks like audio management and enhancing physics simulations.

Q3: Does Unity’s execution order ever change?

A3: No. Unity maintains a consistent execution order for its functions to ensure stability and predictability. The execution order will always be the same, every frame.

Free download: Indie Game Marketing Checklist

Download now

Category

unity basics

Don't forget to share this post!

Popular assets for Unity

See all assets ->
    Cutting-edge volumetric fog and volumetric lighting with support for transparent materials.
    Volumetric clouds, day night cycles, dynamic skies, global lighting, weather effects, and planets and moons.
    A lightweight procedural skybox ideal for semi-stylized projects.
    Image-based Outlines for 2D and 3D games with variable line weight, color, and displacement options.
    Drag-and-drop ready-to-use ambient, impact, and spell particle effects.
    Per-pixel gaussian blur on your entire screen, part of the UI, or in-scene objects.

Free Indie Game Marketing Checklist

Learn how to make your game successful with this handy checklist.

Download for free