# SetActive(bool)

> Activates or deactivates the GameObject locally, according to the value of the supplied parameter.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine](/engine/6000.0/script-reference/unityengine.md)
* **Assembly:** UnityEngine.CoreModule

```csharp
public void SetActive(bool value)
```

### Parameters

**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): The active state to set, where `true` sets the GameObject to active and `false` sets it to inactive.

### Remarks

`SetActive` only sets the local state of the GameObject, represented by the value of [GameObject.activeSelf](/engine/6000.0/script-reference/unityengine/gameobject/activeself.md). Changing the value of [GameObject.activeSelf](/engine/6000.0/script-reference/unityengine/gameobject/activeself.md) has no effect on the value of [GameObject.activeInHierarchy](/engine/6000.0/script-reference/unityengine/gameobject/activeinhierarchy.md) if `activeInHierarchy` is `false` because of an inactive parent object.

Deactivating a GameObject disables each component, including  attached renderers, colliders, rigidbodies, and scripts. For example, Unity will no longer call [MonoBehaviour.Update()](/engine/6000.0/script-reference/unityengine/monobehaviour/update.md) on a script attached to a deactivated GameObject. Deactivating a GameObject also stops all coroutines attached to it.

**Note:** If the call to `SetActive` changes the value of [GameObject.activeInHierarchy](/engine/6000.0/script-reference/unityengine/gameobject/activeinhierarchy.md), this triggers [MonoBehaviour.OnEnable()](/engine/6000.0/script-reference/unityengine/monobehaviour/onenable.md) or [MonoBehaviour.OnDisable()](/engine/6000.0/script-reference/unityengine/monobehaviour/ondisable.md) on all attached MonoBehaviour scripts.

```csharp
using UnityEngine;

public class Example : MonoBehaviour
{
    private GameObject[] cubes = new GameObject[10];
    public float timer, interval = 2f;

    void Start()
    {
        Vector3 pos = new Vector3(-5, 0, 0);

        for (int i = 0; i < 10; i++)
        {
            cubes[i] = GameObject.CreatePrimitive(PrimitiveType.Cube);
            cubes[i].transform.position = pos;
            cubes[i].name = "Cube_" + i;
            pos.x++;
        }
    }

    void Update()
    {
        timer += Time.deltaTime;
        if (timer >= interval)
        {
            for (int i = 0; i < 10; i++)
            {
                int randomValue = Random.Range(0, 2);
                if (randomValue == 0)
                {
                    cubes[i].SetActive(false);
                }
                else  cubes[i].SetActive(true);
            }
            timer = 0;
        }
    }
}
```

Additional Resources: [GameObject.activeSelf](/engine/6000.0/script-reference/unityengine/gameobject/activeself.md), [GameObject.SetGameObjectsActive](/engine/6000.0/script-reference/unityengine/gameobject/setgameobjectsactive.md)
