Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


isActiveAndEnabled

Checks whether a component is enabled, attached to a GameObject that is active in the hierarchy, and the component's OnEnable has been called.
Read time 1 minuteLast updated 6 days ago

Definition

  • Type: Property
  • Namespace: UnityEngine
  • Assembly: UnityEngine.CoreModule
public bool isActiveAndEnabled { get; }

Remarks

Behaviour.isActiveAndEnabled
returns
true
only if all the following conditions are met:
Important: Even if a component is enabled and its GameObject is active,
isActiveAndEnabled
still returns
false
until
OnEnable
is called on the component. This is by design in Unity's scripting lifecyle. For more information, refer to Event function execution order in the User Manual.

Examples

using UnityEngine;using System.Collections;using UnityEngine.UI;public class Example : MonoBehaviour{ public Image pauseMenu; public void Update() { //Checks if the GameObject and Image are active and enabled. if (pauseMenu.isActiveAndEnabled) { //If the Image is enabled, print "Enabled" in the console. Stops when the image or GameObject is disabled. Debug.Log("Enabled"); } }}