I have a gameobject which I wish to activate given a certain condition. I gave it a unique tag and I tried using GameObject.FindObjectWithTag("Tag name").
From what I can tell, this method will only find active gameobjects in the scene and not inactive ones.
Is there a method that I can call that will also search inactive gameobjects? (Preferably searching by tag).
Thanks!
After some research it seems that there is no way to find an inactive gameobject by tag.
solutions exist however to access inactive gameobjects:
1 - Store inactive game objects in an array if you need to reactivate them afterwards (only applies to game objects inactivated at runtime).
2 - Do not deactivate game object, simply deactivate the components you want inactive. If you wish to make the object disappear, deactivate the renderer. If it is a specific script, deactivate that script, etc.
This solution will allow you to still find a game object by its tag name.
Things that can find inactive gameObjects
:
transform.Find() or transform.FindChild()
transform.GetComponentsInChildren<Component>(true)
Resources.FindObjectsOfTypeAll<Component>()
FindObjectsOfTypeAll does find inactive, it just may also find prefabs and things you are not looking for, so you have to be careful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With