- Home /
How to disable all objects but...
How can I disable every object in the scene besides specific ones that that I drag into an array. Right now I am coding every single object that I don't want disabled and this is not efficient and will not work when I have objects in some scenes, but different objects in different scenes. I can't used tags or layers because I already am. Any ideas? Basicly what I am doing is I have the game scene. Once the level is complete disable everything but these few objects to display then level exiting scene where it shows there stats and acheivements.
You can fake this by setting Time.time to zero. Assu$$anonymous$$g you have set up everything right.
I'm trying to understand the underlying issue here. Can you use Object.FindObjectsOfType() to find all the $$anonymous$$onoBehaviours, disable all of them then renable the ones on your list?
http://docs.unity3d.com/ScriptReference/Object.FindObjectsOfType.html
Answer by EvilTak · Nov 05, 2014 at 05:57 AM
if theObjects is your GameObject array which you don't want to disable, then you could use:
GameObject[] allObjects = FindObjectsOfType<GameObject>();
List<GameObject> objectsToDisable = new List<GameObject>(allObjects);
foreach (GameObject a in allObjects) {
foreach (GameObject b in theObjects) {
if (a.name == b.name)
objectsToDisable.Remove(a);
}
}
foreach (GameObject a in objectsToDisable)
a.SetActive(false);
Note that this isn't the most optimized solution, but it does the trick.
Your answer
![](https://koobas.hobune.stream/wayback/20220613170749im_/https://answers.unity.com/themes/thub/images/avi.jpg)