- Home /
Best way to keep track of inactive GameObjects?
I have a lot of GUI-elements that get inactivated and activated. Annoyingly though, you can't find disabled objects with GameObjects.Find("name"), so I need another way to handle this.
Answer by robertbu · Feb 06, 2013 at 06:21 PM
Resources.FindObjectsOfTypeAll() might do the job. There are issues to be careful of when using this method. I'd be tempted to avoid using this call and just keep an array of the object myself. Depending on the nature of the game object, there might be other ways of solving your problem as well (like turning off rendering rather than disabling)
From the reference on FindObjectsOfTypeAll():
*This function can return any type of Unity object that is loaded, including game objects, prefabs, materials, meshes, textures, etc. It will also list internal stuff, therefore please be extra careful the way you handle the returned objects. Contrary to Object.FindObjectsOfType this function will also list disabled objects.
Please note that this function is very slow and is not recommended to be used every frame.*
I've had luck disabling the renderer, rather than the object itself.
Your answer
Follow this Question
Related Questions
How to find Inactive GameObject 16 Answers
Difference between setting GameObjects as active/inactive and loading levels additively? 0 Answers
GameObject.Find() work on inactive objects 16 Answers
gameObject.find doesn't work 1 Answer
How can I generate an infinite world as the player walks through it? 3 Answers