---
title: "Enabling and Disabling Components"
content_type: tutorial
url: "https://learn.unity.com/course/beginner-scripting-old/unit/beginner-scripting/tutorial/enabling-and-disabling-components?language=en"
language: en
container_type: course
container_title: "Beginner Scripting"
container_url: "https://learn.unity.com/course/beginner-scripting-old.md?language=en"
unit_title: "Beginner Scripting"
unit_url: "https://learn.unity.com/course/beginner-scripting-old/unit/beginner-scripting?language=en"
standalone_markdown_url: "https://learn.unity.com/tutorial/enabling-and-disabling-components.md?language=en"
previous_title: "Vector Maths"
previous_url: "https://learn.unity.com/course/beginner-scripting-old/unit/beginner-scripting/tutorial/vector-maths?language=en"
previous_markdown_url: "https://learn.unity.com/course/beginner-scripting-old/unit/beginner-scripting/tutorial/vector-maths.md?language=en"
next_title: "Activating GameObjects"
next_url: "https://learn.unity.com/course/beginner-scripting-old/unit/beginner-scripting/tutorial/activating-gameobjects?language=en"
next_markdown_url: "https://learn.unity.com/course/beginner-scripting-old/unit/beginner-scripting/tutorial/activating-gameobjects.md?language=en"
difficulty: beginner
duration_minutes: 5
unity_version:
  - "2019.3"
  - "2019.2"
  - "2019.1"
  - "2018.4"
  - "2018.3"
  - "2018.2"
  - "2018.1"
  - "2017.4"
  - "2017.3"
  - "2017.2"
  - "2017.1"
  - "5.x"
  - "4.x"
supported_unity_versions:
  - name: "2019.3"
    url: "https://learn.unity.com/tutorial/enabling-and-disabling-components.md?language=en&version=2019.3"
  - name: "2019.2"
    url: "https://learn.unity.com/tutorial/enabling-and-disabling-components.md?language=en&version=2019.2"
  - name: "2019.1"
    url: "https://learn.unity.com/tutorial/enabling-and-disabling-components.md?language=en&version=2019.1"
  - name: "2018.4"
    url: "https://learn.unity.com/tutorial/enabling-and-disabling-components.md?language=en&version=2018.4"
  - name: "2018.3"
    url: "https://learn.unity.com/tutorial/enabling-and-disabling-components.md?language=en&version=2018.3"
  - name: "2018.2"
    url: "https://learn.unity.com/tutorial/enabling-and-disabling-components.md?language=en&version=2018.2"
  - name: "2018.1"
    url: "https://learn.unity.com/tutorial/enabling-and-disabling-components.md?language=en&version=2018.1"
  - name: "2017.4"
    url: "https://learn.unity.com/tutorial/enabling-and-disabling-components.md?language=en&version=2017.4"
  - name: "2017.3"
    url: "https://learn.unity.com/tutorial/enabling-and-disabling-components.md?language=en&version=2017.3"
  - name: "2017.2"
    url: "https://learn.unity.com/tutorial/enabling-and-disabling-components.md?language=en&version=2017.2"
  - name: "2017.1"
    url: "https://learn.unity.com/tutorial/enabling-and-disabling-components.md?language=en&version=2017.1"
  - name: "5.x"
    url: "https://learn.unity.com/tutorial/enabling-and-disabling-components.md?language=en&version=5.x"
  - name: "4.x"
    url: "https://learn.unity.com/tutorial/enabling-and-disabling-components.md?language=en&version=4.x"
last_updated: "2026-08-04T14:22:11.000Z"
---

# Enabling and Disabling Components

Learn to enable and disable components via C# scripts during runtime as part of the Beginner Scripting project.

How to enable and disable components via script during runtime.

This tutorial is included in the [Beginner Scripting project](https://learn.unity.com/project/beginner-gameplay-scripting).

Previous: [Vector Maths](https://learn.unity.com/tutorial/vector-maths?projectId=5c8920b4edbc2a113b6bc26a)

Next: [Activating GameObjects](https://learn.unity.com/tutorial/activating-gameobjects?projectId=5c8920b4edbc2a113b6bc26a)

## 1. Enabling and Disabling Components

[Video](https://connect-mediagw.unity.com/h1/20220104/videos/eed2c14f-7a90-4c40-9bcd-37c5ecd5c959_U_Beginner_10_EnablingandDisablingComponents.mp4) ([Transcript (en)](https://connect-mediagw.unity.com/h1/20220104/75f81622-3520-47ef-8b1d-8a7a08cf1f2b_B_10_Enabling_and_Disabling_Components_V5.0.vtt))

```csharp
using UnityEngine;
using System.Collections;

public class EnableComponents : MonoBehaviour
{
    private Light myLight;
    
    
    void Start ()
    {
        myLight = GetComponent<Light>();
    }
    
    
    void Update ()
    {
        if(Input.GetKeyUp(KeyCode.Space))
        {
            myLight.enabled = !myLight.enabled;
        }
    }
}
```
