Update Vs FixedUpdate Vs LateUpdate In Unity || The Complete Difference

Share on social media

In this article, I will discuss the difference between Update, FixedUpdate, and LateUpdate In Unity. I will try to cover all your questions and queries about all three update methods in unity.

First, let’s begin with understanding what is frame rate in unity. It is important to understand before understanding the difference between Update FixedUpdate, and LateUpdate In Unity, especially if you are a beginner.

Update Vs FixedUpdate Vs LateUpdate In Unity

Read the article till the end for complete information or you can take a quick overview of the article in the below Table Of Content and read the specific part you want.

Frame rate in Unity refers to how many images are displayed on the screen per second. A higher frame rate makes your game look smoother, while a lower frame rate makes it look choppy.

This might make your game feel laggy and less smooth. On the other hand, a higher frame rate means a smooth gameplay experience and animation, and an overall better player experience.

Why Do Frame Rates Vary In Unity?

In unity, frame rates vary and it can cause by several factors that can affect it. 

  1. The complexity of the game, If your game has a lot of objects, Visual FX, and some iterative scripts running at the same time, it can cause the frame rate to drop.
  2. Graphic Settings, Another factor that can affect the frame rate is the graphics settings of your game. Running your game on a high resolution and using high-quality textures can also cause the frame rate to drop.
  3. The performance of your computer, Hardware performance can also play a significant role in determining the frame rate of your Unity game if your computer has a slow processor or an older graphics card or the mobile’s processor if building mobile games.

Now let’s understand one more term which is deltaTime, in this article you will find the uses so it’s important to understand what is it and how it works.

What Is DeltaTime And How It Is Related To Frame Rates In Unity?

DeltaTime is a term used in Unity to refer to the amount of time (in seconds) that has passed since the last frame was rendered. In simple terms, it’s the time between each frame.

For Instance, If you are getting 60 FPS so deltaTime will be 1/60  = 0.0167.

The example above was just for basic understanding, however, this is not the case deltaTime for every Update Method in unity. If you are using LateUpdate or Update, deltaTime varies each frame because the time between each frame is different, on the other hand, if you use the FixedUpdate so it calls in a fixed time stamp and it uses the Fixed deltaTime. it doesn’t execute each frame instead. 

Making Update Calculations Frame-rate Independent In Unity

One of the main use of deltaTime is to make the code frame independent. By using deltaTime you can ensure that game objects move and behave consistently, regardless of the frame rate.

For example, consider a game object that needs to move a certain distance over a certain amount of time. If the game is running at a high frame rate, the object will move quickly, but if the game is running at a low frame rate, the object will move more slowly. This can cause problems if the game’s behavior is dependent on the movement speed of the object.

To make the game frame-independent, the code for moving the object can be written using DeltaTime, which ensures that the object will move the same distance over the same amount of time, regardless of the frame rate. Here’s an example of how DeltaTime can be used to make the object move consistently, regardless of the frame rate:

So before directly jumping into the comparison of the difference between Update FixedUpdate, and LateUpdate In Unity, Let’s first understand each Update Method in unity, what are they, and how they work. Sounds good? Let’s begin.

void Update()
{
    // Calculate the distance the object should move based on its speed and DeltaTime
    float distance = speed * Time.deltaTime;

    // Move the object by the calculated distance
    transform.position += Vector3.forward * distance;
}

In the above code, the distance the object should move is calculated based on its speed and DeltaTime, and the object is then moved by the calculated distance using the += operator. This ensures that the object moves consistently, regardless of the frame rate.

By using DeltaTime in this way, you can make your game more frame-independent, which is essential for ensuring that the game runs smoothly and consistently on a wide range of devices and platforms. When you make your game frame-independent, it will behave the same way regardless of the hardware or performance capabilities of the device, making it more accessible and enjoyable for players. 

Difference Between Update, FixedUpdate, and LateUpdate In Unity

We see what all three Update Methods are and how to use them, now Let’s the difference between them. It’s important to know the differences that will give you a clear picture of their use cases and you will be able to use them efficiently.

Let’s understand the differences between Update, FixedUpdate, and LateUpdate In Unity.

What Is The Update Method In Unity And How It Works?

The Update in unity is the most commonly used method, The update method executes each frame and It derives from the MonoBehaviour class. It can be useful for you to check for player input, move objects, update animations, and perform other time-sensitive actions.

Here is one example of taking player input:

For Example

Let’s say you want to respond to a player pressing the space bar. You can do this by adding a simple piece of code inside the Update method:

public class MyScript : MonoBehaviour
{
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            // Perform an action when the space key is pressed
        }
    }
}

In the above code, we are taking input from the player, so whenever a user will press the ‘space’ key we can perform a certain action.

Now let’s see how to make your update calculation frame rate independent. To make the update method calculations frame independent we can use Time.deltaTime. Let’s understand it with one example.

public float speed = 100f;

void Update()
{
    transform.Translate(transform.right * speed* Time.deltaTime);
}

In the above code, we are moving objects using Translate in the update method. We are multiplying the speed with the TIme.deltaTime. It will make the movement more constant over each frame and fluctuations in the frame won’t affect the object’s movement.

So this way you can make the update calculations Frame-Independent. There are many other examples of using the Update in unity such as using Raycast In Unity.

One thing to keep in mind with the Update method is that it is not called at a fixed time interval, which can lead to some variability in performance. If your game logic requires precise timing or synchronization with other game elements, you may need to use FixedUpdate or LateUpdate instead.

What Is The FixedUpdate Method In Unity And How It Works?

FixedUpdate is a Frame Independent Update Function In unity and it also helps you keep your physics calculations in sync with the physics engine. Unlike the Update method, which runs once per frame, FixedUpdate runs at a fixed interval set by the physics system. This interval is set in the Unity Editor and is typically set to 0.02 seconds, meaning FixedUpdate will be called 50 times per second.

You can change it in Edit > Project Settings > Time > Fixed Timestep. 

Fixed deltaTime In Unity

The FixedUpdate frequency can be more or less than the Update method. If you are getting 25 FPS in the game then the FixedUpdate will be called twice per frame.

One of the big advantages of FixedUpdate in unity is that it runs consistently and deterministically, regardless of how fast or slow your game is running. This makes it perfect for updating the position or velocity of rigidbodies, which are affected by the physics engine.

So, if you want to make sure your physics calculations are running smoothly, you should use FixedUpdate instead of Update. Just keep in mind that FixedUpdate should only be used for physics updates. If you want to make non-physics updates, it’s best to use Update Or LateUpdate instead.

Let’s understand it with one example.

For Example

Let’s say you have a ball in your game that you want to drop under the influence of gravity. You would create a script and attach it to the ball object, and in the script, you would use the FixedUpdate method to update the ball’s position based on its velocity and acceleration due to gravity.

Here’s what the script might look like:

using UnityEngine;

public class Ball : MonoBehaviour
{
    private Rigidbody rigidbody;
    private Vector3 velocity;
    private float gravity = 9.8f;

    private void Start()
    {
        rigidbody = GetComponent<Rigidbody>();
        velocity = Vector3.zero;
    }

    private void FixedUpdate()
    {
        velocity += Vector3.down * gravity;
        rigidbody.position += velocity;
    }
}

In this example, the FixedUpdate method is used to update the ball’s velocity and position based on the acceleration due to gravity. By using the FixedUpdate method, we ensure that the physics calculations are performed consistently and deterministically, regardless of the frame rate. You can also check the call frequency of the FixedUpdate in unity by using the Time.fixedDeltaTime.

I hope this example helps you understand how to use the FixedUpdate method in Unity.

What Is The LateUpdate Method In Unity And How It Works?

The LateUpdate method is a part of the MonoBehaviour script that you can attach to your objects in Unity. It’s similar to the Update method in that it’s called once per frame, but it’s unique in that it’s called after all other updates have been processed. This makes it a great option for updates that require the latest information from other components, such as the camera or lighting system.

Let me give you an example of how you can use the LateUpdate in unity. Have you ever wanted to make a camera follow a player in a game? This is the perfect use case for the LateUpdate method. By updating the camera position after all other updates have been processed, you can make sure that the camera always stays right behind the player.

Here’s a simple script to show you how it’s done:

using UnityEngine;

public class CameraFollow : MonoBehaviour
{
    public Transform target;
    public float smoothSpeed = 0.1f;
    
    // You can make it public and can set it accordingly 
    private Vector3 offset = new Vector3(0, 0, -5);
        
    private void LateUpdate()
    {
        SmoothFollow(); 
    }

    public void SmoothFollow()
    { 
        Vector3 targetPos = target.position + offset;
        Vector3 smoothFollow = Vector3.Lerp(transform.position,
            targetPos, smoothSpeed);

        transform.position = smoothFollow;
        transform.LookAt(target);
    }
}

In this script, the LateUpdate method updates the camera’s position to smoothly follow the position of the target, which is represented by the player transforms component. This way, the camera will always be right behind the player, no matter where the player goes.

  • How to make a smooth camera follow in unity c#?

Another use for the LateUpdate method is for special effects that depend on the final positions of all objects in the scene. For example, you could use LateUpdate to apply a full-screen post-processing effect that requires information from the camera and the lighting system. By waiting until all other updates have finished, you can be sure that you have the latest information available for the best possible result.

It’s important to keep in mind that the LateUpdate in unity is the method that should only be used for updates that require the latest information from other components. For normal updates, it’s best to stick with the Update method.

I hope this helps you understand the LateUpdate method in Unity and how you can use it. Now let’s understand the differences between all three update methods in unity.

Order Of Execution Of Update Methods In Unity

Let’s understand the order of execution of all three update methods. So, the order of execution in Unity is as follows:

FixedUpdate method: Called once per fixed frame, determined by the physics engine. Good for physics calculations and game logic that is tied to the physics system. FixedUpdate executes before any other update in unity.

Update method: Called once per frame, before any physics calculations are performed. Good for user input, animations, and other fast updates. It executes after the FixedUpdate and Before the LateUpdate.

LateUpdate method: Called once per frame, It executes after all other update methods execute. Good for camera updates, post-processing effects, and other updates that require the latest information.

We can also check it through code. Let’s create one script which will track the call of each Update in unity and we will print the logs for each update method.

Here is the code to check the order of execution of all three update in unity.

using UnityEngine;

public class UpdateTest : MonoBehaviour
{
    bool continueUpdate=true;
    bool continueFixedUpdate=true;
    bool continueLateUpdate=true;
    
    // FixedUpdate is called before Update, at Fixed deltaTime 
    void FixedUpdate()
    {
        if(continueFixedUpdate)
        {
            Debug.Log("Fixed Update");
            continueFixedUpdate=false;
        }
    }

    // Update is called once per frame
    void Update()
    {
        if(continueUpdate)
        {
            Debug.Log("Update");
            continueUpdate=false;
        }
    }
    // Late Update is called after update
    void LateUpdate()
    {
        if(continueLateUpdate)
        {
            Debug.Log("Late Update");
            continueLateUpdate=false;
        }
    }
}

Here is console logs of the above code:

Update Vs FixedUpdate Vs LateUpdate

Hope this would have helped you to understand the order of execution of all the update in unity. 

Now let’s see the differences: Update Vs FixedUpdate Vs LateUpdate

Update Vs FixedUpdate Vs LateUpdate

Update Vs FixedUpdate

Let’s understand the difference between Update and FixedUpdate.

The Update method is called once per frame and Its Frame-rate is dependent. It is useful for taking the player input, player movement, updating animations, and performing other time-sensitive actions or any game logic. You can make the calculations Frame-rate Independent by using Time.deltaTime.

On the other hand, FixedUpdate is called in a fixed time stamp which is defined under the time settings in unity. It’s a time-dependent Method, can also say it is Frame-rate independent. It’s used to handle the physics calculations or any calculations that need to happen at a constant rate or any other game logic that is tied to the physics system.

It’s important to choose the right method for the right type of update in your game. For fast, real-time updates, use the Update method. For physics-related updates and game logic, use the FixedUpdate method.

Now let’s understand it by some examples.

For Example, We can understand the differences by moving the Rigidbody in both the update methods and comparing the results that will help you to see the differences.

Let’s create a script to move a Rigidbody using AddForce In both Update and FixedUpdate and then we will compare the results of both.

using UnityEngine;

public class UpdateTest : MonoBehaviour
{
    [SerializeField] private bool useUpdate = true;
    [SerializeField] private bool useFixedUpdate = true;

    private Rigidbody rigidbody;
    private float force = 10;

    private void Start()
    {
        rigidbody = GetComponent<Rigidbody>();
    }
    
    void FixedUpdate()
    {
        if (useFixedUpdate)
        {
            rigidbody.AddForce(Vector3.up * force);
        }
    }
    
    void Update()
    {
        if (useUpdate)
        {
            rigidbody.AddForce(Vector3.up * force);
        }
    }
}

Here is the result of the above code

As you can see in the above representation, the FixedUpdate Cube is moving more constantly and steadily whereas Cube with the Update function is moving way faster.

The reason is that the Update function executes each frame, on the other hand, FixedUpdate executes on the fixed time stamp. The update calling frequency is greater than FixedUpdate that’s why the Cube with Update method is going faster that the one with FixedUpdtae

It can also be reversed if you are getting 25 FPS, in that case, Cube with FixedUpdate will move faster. It also doesn’t mean that Cube with Update method can’t be moved constantly and steadily, we can use Time.deltaTime as a multiplier which will make the movement constant and will make it Frame-Rate Independent. But I would still not suggest doing physics calculations in the Update Method.

I hope this would be helpful to understand the difference between Update and FixedUpdate In Unity.

Update Vs LateUpdate

Let’s understand the difference between Update and LateUpdate.

When it comes to updating the state of your game, Unity provides you with two methods – Update and LateUpdate – to choose from. Understanding the difference between these two methods is necessary to make the code optimized.

We already know that The Update method is called once per frame and is used to handle real-time updates that need to happen as quickly as possible. This might include things like processing user input, playing animations, and updating the positions of objects in real time.

On the other hand, LateUpdate is called once per frame, after all, other updates have been called, including the physics calculations. This makes LateUpdate a good place to handle updates that require the latest information about the state of your game because all the updates already have been made. 

For example, you might use LateUpdate to update the position of a camera so that it always follows the player, or to apply post-processing effects to the scene. Because LateUpdate is called after all other updates have been called, you can be sure that you’re working with the latest information about the state of your game.

In summary, the key difference between Update and LateUpdate is when they’re called about the rest of the updates that are being called. If you need to handle real-time updates that need to happen as quickly as possible, use Update. If you need to handle updates that require the latest information about the state of your game, use LateUpdate.

I hope this explanation helps you understand the difference between Update and LateUpdate in Unity.

Time.deltaTime Vs Time.fixedDeltaTime

Time.deltaTime: As you may already know, DeltaTime is a time variable in Unity that represents the time that has passed since the last frame was rendered. This value is used to make game objects move and behave consistently, regardless of the frame rate. However, there’s another time variable in Unity called fixedDeltaTime, which has some key differences from DeltaTime.

Time.fixedDeltaTime: Unlike DeltaTime, fixedDeltaTime is a fixed time interval that represents the time between fixed updates in Unity. Fixed updates are a feature in Unity that allows developers to update physics and other time-dependent calculations at a fixed interval, rather than at every frame. This can be useful for creating more consistent physics simulations and for reducing performance issues related to fluctuating frame rates.

When should you use deltaTime Vs fixedDeltaTime in your unity?

The answer depends on what you’re trying to accomplish. If you’re working on physics simulations or other time-dependent calculations that require a fixed time interval, fixedDeltaTime and FixedUpdate() are likely the better options. However, if you’re working on general game logic that needs to be frame-independent, DeltaTime and Update() are likely the better options.

In conclusion, both DeltaTime and fixedDeltaTime have their uses in Unity game development. By understanding the differences between these time variables and when to use them, you can create games that are more consistent, performant, and enjoyable for players.

Common Mistakes When Using Update Methods

When using Update, FixedUpdate, and LateUpdate in Unity, it’s important to avoid some common mistakes that many developers make especially beginners. These mistakes can affect your game’s performance. Here are some common mistakes to avoid:

Taking References In Update Methods: Many developers take the references in the update methods which is not a good practice to do. Whenever it is possible of taking references in Update try to use Start or OnEnable Instead

Overusing Update: Putting too much code in Update can slow down your game, so it’s best to limit what you put there. Instead, move time-sensitive calculations to FixedUpdate and updates that need the latest information to LateUpdate, and for player movements or player input use Update in unity. Separate things according to their use cases.

Not Using FixedUpdate For Physics Calculations: This method is designed for updates related to physics and other time-sensitive operations, so make sure to use it when needed. It is not recommended to use Physics calculations in Update or LateUpdate so make sure to use FixedUpdate.

Making your code too complicated: Keep your code simple and efficient to help your game run smoothly. Don’t make the code too complicated.

By being aware of these common mistakes, you can help keep your game running smoothly and efficiently, even as it grows more complex.

Conclusion

In this article, we saw the complete difference between Update, FixedUpdate, and LateUpdate in Unity. each update method in unity serves different purposes and is used for different types of updates in your game. 

The Update method is called every frame and is used for time-sensitive updates that need to happen as quickly as possible. 

The FixedUpdate method is called at a fixed rate and is used for physics and other time-sensitive operations. 

The LateUpdate method is called after all Update and FixedUpdate calls have been made and are used for updates that require the latest information about your game’s state. 

Understanding the differences between these methods and using them correctly can greatly improve the performance and stability of your Unity games.

In the end, I also want to suggest you one plugin that I use in my projects to move the objects, it is DOTween. It makes your work easier.

I hope you may have learned something new today and this article was helpful for you. Feel free to ask your questions or query in the comment below 🙂

FAQs

Here are some frequently asked questions related to the difference between Update, FixedUpdate, and LateUpdate In Unity.

Which Update Method Will Execute If Time.timeScale Is 0

If Time.timeScale is set to 0 then FixedUpdate will not be executed but Update and LateUpdate Methods will execute. The reason is that the FixedUpdate is Time-dependent Method while the other two is Frame Dependent so they are affected by Frames, not by Time.

But Update and LateUpdate can also be affected by it if you are doing calculations that are using Time.deltaTime as a multiplier since Time.timeScale is 0 Time.deltaTime will also be 0 and the output of your calculations will be 0. It doesn’t mean Update Or LateUpdate is not working it’s just that you are multiplying with 0.

For Example: Let’s say you are moving an object in Update Method which uses Time.deltaTime. If you make the time.timeScale 0 then the object will stop moving because eventually speed will be 0 but other calculations will be working which do not use Time.deltaTime.

Can I use Update for physics-related updates?

You can use Update for physics-related calculations but it is not recommended to use it. it’s better to use FixedUpdate for this purpose, as FixedUpdate is designed specifically for physics and other time-sensitive operations.

What happens if I use FixedUpdate for non-physics-related updates?

You can use FixedUpdate for non-physics calculations but it is recommended to use Update or LateUpdate instead. it’s better to use FixedUpdate since it is designed specifically for physics and other time-sensitive operations.

Should I always use LateUpdate for camera updates?

Yes, using LateUpdate for camera updates is a common practice, as it ensures that the camera has access to the latest information about your game’s state before it performs its updates. 

LateUpdate is the best choice for camera follow because you know that FixedUpdate and Update have been executed and you have the latest transform positions to follow.

I hope now you understand the difference between Update, FixedUpdate, and LateUpdate In Unity. But If you still have any questions or queries please feel free to ask in the comments 🙂

Aakash Solanki
Aakash Solanki

I am a professional unity game developer. I have a passion for creating immersive gaming experiences. For me writing articles feels like giving back to the community we have learned from. My hobbies involve playing games and writing articles and sometimes I also create youtube videos.


Share on social media

1 thought on “Update Vs FixedUpdate Vs LateUpdate In Unity || The Complete Difference”

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top