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
110

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 functions are execution order and run conditions.

Awake functions run before the Start 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 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");
    }

Conclusion

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