Unity Awake vs Start: What is the Difference?

Unity has a lot of predefined functions that you can use in your game scripting. Awake and Start are two of such functions. But, there is so much confusion on these functions that Unity Awake vs Start is one of the most searched terms online. In this post, we will see how these functions work and which one to be used where. In all my years of game development, I honestly didn’t need to think much about the Awake function. Most of my game scripts comprise of the Start function. Awake is used very rarely in scripts and can be very useful at some times.

In brief, the difference between awake and start is as the name suggests. Awake is when the script of the object is added to the scene and Start is when the script starts doing something. This is just a basic idea of when Start and Awake functions are called.

Unity Awake vs Start

Let’s Start with what Unity says

Unity Awake ()

Awake is called when the script instance is being loaded. Awake is called either when an active GameObject that contains the script is initialized when a Scene loads, or when a previously inactive GameObject is set to active.

Unity documentation

Unity Start()

Start is called on the frame when a script is enabled just before any of the Update methods are called the first time.

Unity documentation

Now let’s try and understand what they say.

Awake function in a script of a gameobjects is called when the scene containing the gameobject is loaded. The only time Awake is not loaded is when the gameobject is disabled.

The Start function is called when the script is initialized. If you keep the script disabled then Start will not be called.

The common thing about Unity Start and Awake function is both these functions get called only once and both the functions are called after object initialization. So, it is safe to check for other gameobjects in the scene in both Awake and Start.

Unity Awake vs Start with examples

Testing Unity Awake()

Let’s take 3 Gameobjects in a scene g1,g2,g3. I will add a script to each game object with an Awake and a Start function. Inside all these functions I will add a debug log. Here is the sample code. The debug log contains the number based on the gameobject, i.e in g1, it’s awake1, and in g2 it’s awake 2 so on.

using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 public class test3 : MonoBehaviour
 {
     void Awake()
     {
         Debug.Log ("Awake1 called");
     }
    
     void Start()
     {
     } 
 }

Scenario one: All gameobjects and scripts are enabled.

In this scenario, we will keep all the gameobjects and their respective scripts enabled. Then lets hit play and see the debug log.

Unity output 1

As you can use when the game scene was loaded Awake() of all the gameobjects were called. All three debug log were displayed on the console.

Scenario Two: All scripts in Gameobjects are disabled, but the gameobjects are enabled.

We will keep the gameobjects active in the hierarchy but disable the script attached to all the gameobjects.

Unity output 2

Even when the scripts were disabled, their Awake() function was called. This shows that irrespective of the status of the script the awake function is called if the gameobject is active in the hierarchy.

Scenario Three: Mixing things up to see the result.

g1 and it’s script is enabled, g2 script is disabled in inspector and g3 gameobject is disabled in the hierarchy.

Unity output 3

Awake of g1 and g2 got called but g3 was not called. Now let’s enable g3. As soon as I enabled g3 the Awake function gets called.

The conclusion from the above experiment is that the Awake function will be called at scene load if the object is set active even if the script is disabled.

Testing Unity Start()

I am going to use the same setup and scenario which was used for testing Awake. I will shift the log statement to the Start function. Same gameobject g1,g2,g3 are used for testing the Start function.

Scenario One: All gameobjects and scripts are enabled

Unity output 4

All start function gets called on scene load. You can see all the debug log appearing on the console window.

Scenario Two:All scripts in Gameobjects are disabled, but the gameobjects are enabled.

Unity output 5

None of the start functions are called in this case. Unlike the Awake function, the Start function is not called if the script is disabled.

Scenario three: g1 and it’s script are enabled, g2 script is disabled and g3 gameobject is disabled

Unity output 6

Start function of g1 is called but g2 and g3 are not called. When I enable the script attached to g2 the Start function gets called.

This makes it more clear that the Awake function is more gameobject dependent and the Start function is more script dependent.

Still, confused? Let’s see an Analogy of Unity awake vs Start

Take a team of 20 people being considered by the selection board for a football match. Out of these 20, only 15 will be in the squad and only 11 will play the game.

Let’s do a Unity Awake vs Start comparison with these players. Assume that an Awake() and a Start() function is attached to all these players.

Players who are not in the squad are like disabled gameobjects. Their Awake() function never gets called. Only the player who makes it to the squad gets their Awake functions called.

When the squad is announced the Awake() function of the 15 players in the squad gets called and when the match starts only the playing 11’s Start function gets called and when a player is substituted, at that time the Start function of the player entering the ground is called. But, the Awake function of the substituted player is called well before the substitution.

In-Game Unity Awake vs Start: where they can be used

  1. Initializing public variable- Better done in Awake, as other gameobject might reference them.
  2. Checking for gameobjects and their components- can be done in both Awake and Start.
  3. Initializing gameobject specific variable like health- Better to be done in Start.
  4. Need delayed Initialization- Can be done in Start, Awake call cannot be delayed.
  5. Set all player ammo to zero on scene load- can be done in Awake. Ammo will be set to zero even if the script is disabled.

Hope this has cleared your doubts on Unity Awake vs Start functions. If you have any other queries, feel free to leave a comment below. You can also check out more Unity tutorials here.

1 thought on “Unity Awake vs Start: What is the Difference?”

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: