Skip to main content
Unity3D

Unity3D Scripting API #7: Awake() ☀️

By January 27, 2021February 14th, 2021No Comments
Unity3D Scripting API

⭐Event methods get called automatically by the Unity3D engine at predetermined times.

☀️Called only once in the lifecycle of a script
☀️Called even if the script component is disabled
☀️It is an initialization method like Start() . Called at the beginning when game objects are created and initialized. Awake()  is called when the object that the script is attached to is initialized
☀️ Usage: Awake() is used to initialize any variables, properties, or game state of an object before the game starts . Initializing variables and current object properties that do not depend upon any other variable or object property. It will also create any references between scripts

Difference between Awake() and Start():

☀️Called before Start()🏁Called after Awake()
☀️Called even if the script component is disabled🏁 Called only if script component is enabled
☀️Initializing variables and current object properties that do not depend upon any other variable or object property🏁Initializing variables and current object properties that depend upon any other variable or object property

☀️ Each object’s Awake() is called randomly, so don’t put code that depends on another objects properties or methods here

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CubeController : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        Debug.Log("Start");
    }
 void Awake()
    {

        Debug.Log("Awake");

    }

}

Leave a Reply