Update Method – Unity


In this article we are going to analyze Unity’s Update method which allows us to make changes over time in our projects.

A method is a function defined in a script that can be executed and performs the task we define inside it. To learn more about methods in programming you can read this article or watch a video that summarizes the information.

Before continuing I leave a video in which I did some tests in Unity to better understand the methods Start, Update and FixedUpdate and how is the order of execution of them. To understand this will help you to detect the moments in the execution of the code in which it is convenient to carry out this or that task.

Update Method in Unity – MonoBehaviours

The Update function is defined in the MonoBehaviour class and will run automatically in each frame of the game if the MonoBehaviour is active.

When we create a new Script in Unity, by default we’ll get some code already written. In this code is defined a Programming Class that is called equal to the name that we gave to the Script and that extends or inherits its behavior of MonoBehaviour, this in simple terms means that our Script is in itself a MonoBehaviour or a particular case of MonoBehaviour.

MonoBehaviours can be added to the GameObjects that are in the hierarchy, this can be done from the inspector using the “Add Component” button or simply dragging the Script to the GameObject inspector.

Execution of the Update function

When running the game, Unity will automatically take all the MonoBehaviours in the scene and perform the Update methods before displaying each frame in the game. So we don’t have to do the execution of this method manually, the engine takes care of it.

This means that the Update function will run periodically while our game is running.

If our game runs at 60 FPS (frames per second) the Update function will run 60 times per second.

Conclusion – Update for changes in time

The Update method represents everything that is dynamic in our game, when we want to produce changes in time Update is one of the functions that we have to consider.

It is useful to understand the order of execution of the Start, Update and FixedUpdate methods since it allows us to identify different moments in the execution of the game.

Leave a Comment

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