Vigyata.AI
Is this your channel?

Unity onEnable and onDisable Explained for Beginners!

134 views· 5 likes· 3:01· Jun 26, 2025

In this Unity tutorial, we dive into the powerful OnEnable() and OnDisable() methods.Learn how these functions automatically respond when a GameObject is activated or deactivated in your scene. Using a simple color-changing example, we demonstrate:🟢 How the object turns green when active🔴 How it turns red when inactive🖱️ How clicking the object temporarily deactivates it and then reactivates it after 2 seconds. Timeline: 00:00 - Intro 00:09 - What are OnEnable & OnDisable 00:48 - Start Coding 02:23 - Testing This is a great way to understand object lifecycle events and manage your game objects efficiently. Whether you’re a beginner or looking to polish your Unity skills, this video will help you master these essential MonoBehaviour callbacks. Don’t forget to LIKE, COMMENT, and SUBSCRIBE for more Unity tips and tutorials! #Unity #UnityTutorial #OnEnable #OnDisable #GameDevelopment

About This Video

In this quick Unity tutorial, I break down two tiny-but-powerful MonoBehaviour callbacks: OnEnable() and OnDisable(). These are built-in methods Unity calls automatically when a GameObject becomes active or inactive—so you don’t manually invoke them. I explain when each one fires (scene load, SetActive(true), and SetActive(false)) and why they feel like part of Unity’s event-driven system: Unity watches the object state, and the moment it changes, these callbacks run. To make it super clear, I code a simple color-changing example using a Renderer reference. I grab the Renderer in Awake (small correction from Start—Awake is better here because I want the component ready as early as possible), then I use OnEnable to turn the object green and OnDisable to turn it red. I also show what happens when you click the object with OnMouseDown: I deactivate it immediately (triggering OnDisable), then use Invoke to reactivate it after 2 seconds (triggering OnEnable again). The big takeaway: even though disabled objects don’t render and won’t run Update/physics, OnDisable still runs right before it disappears—making it a perfect place for cleanup, saving data, or stopping effects.

Frequently Asked Questions

🎬 More from Casayona Code