unity

Difference Between Update and FixedUpdate

Update_FixedUpdate

Objective :

The objective of this post to understand the difference between Update and FixedUpdate unity function, and their uses.

Update :

  • Update is called once per frame, so if the game is running at 24 fps, then this will be called 24 times in a second.
  • As we know game never run at constant frame rate because of several reason, so update will not be called on a regular timeline, means the time between update calls may be different.

Uses:

  • Update is used for moving non physics objects.
  • Update is used for receiving Input.
  • Update is used for simple timer.

Fixed Update:

  • As it name suggests this will be called after fixed time duration, so time duration between two consecutive calls is always same unlike of Update where this may vary.

 Uses :

  • This is commonly used for performing physics related task, like applying force on rigidbody.

Now let’s see this in example

Create a new C# script and paste this code, attach it to your main camera and see the logs in console window


public class Update_FixedUpdate_Log : MonoBehaviour {

 void Update ()
 {
   Debug.Log("Update is called after time : "+Time.deltaTime);
 }

 void FixedUpdate()
 {
   Debug.Log("Fixed Update is called after time : "+Time.deltaTime);
 }
}

it will look like this

update_fixedupdate

 

So this makes it clear that FixedUpdate is getting called after regular interval of time, whereas Update is getting called at irregular timeline.

Please comment below, if you have any query related to this.

Reference:

Unity Forum

StackOverflow

 

2 comments

  1. Pingback: Unity Interview Questions – Unity Geek

  2. Pingback: The week in .NET – 7/19/2016 | .NET Blog

Leave a Reply

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