Legacy Documentation: Version 4.5.0

Script language:

  • JS
  • C#
  • Boo
Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

GameObject.SetActive

SetActive(value: bool): void;
void SetActive(bool value);
def SetActive(value as bool) as void

Description

Activates/Deactivates the GameObject.

Note that a GameObject may be inactive because a parent is not active. In that case, calling SetActive() will not activate it, but only set the local state of the GameObject, which can be checked using GameObject.activeSelf. This state will then be used once all parents are active.

See Also: GameObject.activeSelf, GameObject.activeInHierarchy.

	// Deactivates the game object.
	gameObject.SetActive (false);
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    void Example() {
        gameObject.SetActive(false);
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	def Example() as void:
		gameObject.SetActive(false)