Skip to main content

Unity3D Scripting API #8: OnEnable() 🕹️

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

⭐ OnEnable():

⭐Event methods get called automatically by the Unity3D engine at pre-determined times

 🕹️Called after Awake()                             
🕹️Called whenever the script component is enabled which can be more than once      
🕹️ Usage: Resetting variables and current object properties. Or for executing code when the script component is enabled    
🕹️ Start() is called once, OnEnable() is called every time the script component, or the object it’s attached to is enabled.    
🕹️ OnEnable() isn’t suitable for initialization tasks that only need to happen once.

Order of execution of Awake(), Start() and OnEnable()

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

public class CubeController : MonoBehaviour
    // Start is called before the first frame update
    void Start()
 void Awake()

 void OnEnable()
        Debug.Log("On Enable");
Order of execution

☀️ Usage: Awake() is used to initialize any variables, properties, or game state of an object before the game starts

🍩Start(): This method is called on the first frame of the game before

🕹️ OnEnable(): Called whenever the script component is enabled (can be more than once)

Leave a Reply