- Home /
Disable a component for every instance of a prefab
Is there a way to disable a component in every instance of the same prefab in my scene ?
Answer by MickyX · May 03 at 02:58 PM
What I would do
Assuming you are instancing the prefab at runtime?
Create a list and add the instances to a list, then you have a reference to them and can disable the component by iterating through the list.
If not instancing at runtime you can still create a list and assign them to that list in the editor
If you can tag them all, you can use - Slower than the above and requires the use of a tag so I wouldn't recommend
FindGameObjectsWithTag(string tag); and iterate through the results
I wouldn't recommend the below - AT ALL but technically it would work You could loop through all objects in the scene and check if it has the component you are looking for and disable it, or is named like you want it and then disable the component.
Mike
I think tags would do the trick, as i use polybrush to place my prefabs, thanks a lot !
Your answer
![](https://koobas.hobune.stream/wayback/20220613060125im_/https://answers.unity.com/themes/thub/images/avi.jpg)