# How disable all Scripts

**URL:** https://discussions.unity.com/t/how-disable-all-scripts/638570
**Category:** Scripting
**Tags:** Scripting
**Created:** [September 1, 2016, 10:52pm UTC](https://discussions.unity.com/t/how-disable-all-scripts/638570 "2016-09-01T22:52:40Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![psyhova](https://avatars.discourse-cdn.com/v4/letter/p/a88e57/32.png) [@psyhova](https://discussions.unity.com/u/psyhova)
#### Post date: [September 1, 2016, 10:52pm UTC](https://discussions.unity.com/t/how-disable-all-scripts/638570/1 "2016-09-01T22:52:40Z")

</div>

How can I disable all scripts of Objects, that are tagged? I have Objects tagged as bacteria, they have a script attached. Now I want to disable the scripts attached to this tagged Objects.

Bakterien = gameObject.FindGameObjectsWithTag(“Bacteria”);

If (switch) // bool to activate the disable Option  
{  
for (var Bac:GameObject in Bakterien)

{  
Bac.GetComponent(ScriptName).enabled =false;

}  
}

It does not find the Script It gives me a Null reference Exception.  
Does anybody know whats wrong with the simple code above???

Thanx

---

<div class="post-metadata">

### Author: ![DonLoquacious](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/donloquacious/32/333500_2.png) [@DonLoquacious](https://discussions.unity.com/u/DonLoquacious)
#### Post date: [September 1, 2016, 11:04pm UTC](https://discussions.unity.com/t/how-disable-all-scripts/638570/2 "2016-09-01T23:04:11Z")

</div>

At some point during the loop, it’s not finding a component “ScriptName” and you’re trying to disable the script anyways. A simple null-check there would suffice, like:

```javascript
var someComponent : ScriptName = Bac.GetComponent<ScriptName>();

if(someComponent != null)
    someComponent.enabled = false;

```

or you can just disable the whole GameObject with Bac.SetActive(false); A disabled GameObject will have all of its scripts disabled too for the duration. Worth noting that even disabled scripts can still be accessed just fine- it’s only the automated function calls like Start, Update, LateUpdate, etc that won’t fire.

---

<div class="post-metadata">

### Author: ![mahdiii](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/mahdiii/32/546301_2.png) [@mahdiii](https://discussions.unity.com/u/mahdiii)
#### Post date: [September 1, 2016, 11:12pm UTC](https://discussions.unity.com/t/how-disable-all-scripts/638570/3 "2016-09-01T23:12:24Z")

</div>

maybe your ScriptName is not a component of your gameobject and it belongs to the children component.  
Also your gameobjects must be enable to able to find them,

---

<div class="post-metadata">

### Author: ![DonLoquacious](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/donloquacious/32/333500_2.png) [@DonLoquacious](https://discussions.unity.com/u/DonLoquacious)
#### Post date: [September 2, 2016, 12:26am UTC](https://discussions.unity.com/t/how-disable-all-scripts/638570/4 "2016-09-02T00:26:21Z")

</div>

> [@mahdiii](#):
>
> maybe your ScriptName is not a component of your gameobject and it belongs to the children component.  
> Also your gameobjects must be enable to able to find them,

True about the FindObjectsWithTag only finding active GameObjects, but if it didn’t find a result then the array would be empty and the loop wouldn’t run- no error. The “script it on the child” angle is definitely possible- try [GetComponentInChildren()](https://docs.unity3d.com/ScriptReference/Component.GetComponentInChildren.html) instead of GetComponent() if that’s the case, to return the first instance of the script found on the component or on one of its children. Note that it returns the component attached to the GameObject itself if one exists, and won’t check the children unless the component isn’t found there- the name is a bit misleading in that sense.
