Sharp Coder is reader-supported, meaning when you buy through links on our site, we may earn an affiliate commission.
HomeBlogUnityProgramming

Awake vs Start

0 Comments ยท May 27, 2021
529

Scripting API in Unity provides a set of initialization functions.

Initialization functions are the functions that are called at the start of the script lifecycle.

Unity's initialization functions are Awake and Start.

Awake vs Start

The differences between Awake and Start are execution order and run conditions.

Awake functions run first, regardless if the script is enabled or not, and Start functions only run when the script is enabled. Both functions run before the first Update method.

    void Awake()
    {
        Debug.Log("Awake runs first");
    }

    void Start()
    {
        Debug.Log("Start runds second");
    }

Start function can also be a Coroutine (by replacing void with IEnumerator and adding a yield parameter), but Awake function can not.

    IEnumerator Start()
    {
        //Wait 1 second before running the next code
        yield return new WaitForSeconds(1);

        Debug.Log("Start");
    }

Takeaway

Both functions are useful for initialization purposes (ex. assigning private variables, spawning game objects, etc.), and when used in combination, can help to implement a wide variety of scenarios.

You Do Not Have To Do Everything Yourself
Search from thousands of ready-to-use Unity assets.
Visit Asset Store