Teaching Newbies since 2014

kauress

  • Home
  • Javascript ❤
    • JavaScript
    • Node.js
  • WebDev Tuts
  • screencasts
  • Resources
  • VR & AR
  • Contact
  • Github
  • Twitter
  • YouTube
  • RSS
  • C++
You are here: Home / Unity3D / Unity3D Scripting API #7: Awake() ☀️

January 27, 2021 by: Kauress

Unity3D Scripting API #7: Awake() ☀️

⭐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");

    }

}
Unity3D Scripting API #6: LateUpdate()☑️
Introduction to C# in Unity3D #3: Data Types 🌌

Leave a Reply Cancel reply

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

Copyright © 2021 ·Kauress