Find inactive gameobject by tag in unity3d

I have a game object that I want to activate, given a certain condition. I gave it a unique tag and I tried to use GameObject.FindObjectWithTag("Tag name"). From what I can say, this method will only find active game objects in the scene, not inactive.

Is there a method that I can call that will also look for inactive game objects? (Preferred search by tag).

Thanks!

+7
source share
3 answers

After some research, it seems that there is no way to find an inactive game object by tag.

However there are solutions

to access inactive game objects:

1 - Store inactive game objects in the array if you need to reactivate them (applies only to game objects inactive at run time).

2 - Do not deactivate the game object, just disable the components that you want to disable. If you want the object to disappear, turn off the renderer. If it is a specific script, deactivate the script, etc.

This solution will allow you to find a game object by the name of its tag.

+12
source

Things that inactive gameObjects can find:

 transform.Find() or transform.FindChild() transform.GetComponentsInChildren<Component>(true) Resources.FindObjectsOfTypeAll<Component>() 

More details

+5
source

FindObjectsOfTypeAll is really inactive, it can also find collections and things that you are not looking for, so you have to be careful.

+1
source

All Articles