Find deactivated game object

It seems GameObject.Find() only gets active objects. Is there a function to get any object activated or not? I know I can save off these objects to a variable before I deactivate them but it would just be easier and cleaner to be able to have a function that gets any game objects no matter what.

AFAIK there is no method of finding inactive game objects built in; you’ll need to roll your own. However, it’s only a few lines of code to make a quick “SafeReference” script which does something like.

void Start(){
GameManager.Instance.AddReference(gameObject);
}

And drop it on/add it as a requirement to whatever classes you are toggling active/inactive in your game. Then, instead of using GameObject.Find you can just search through the list stored in your GameManager. It is faster that way anyhow (since you’ll only be iterating over objects which are potentially valid).

Instance.AddReference is not in the documentation… how to use it?

I ran into this issue, myself. Was kind of annoying. ><

Anyway, what I ended up doing was putting the GameObject I wanted to be able to activate or deactivate in a GameObject I that would always be active. Meaning I’d follow up any GameObject.SetActiveRecursively(false) calls with GameObject.active = true.

I was also looking for the answer. But what I did is that Store the reference of whatever the game object is going to hide on unity’s Awake() method and then activate them by using reference variable. it worked for me.

Please dont resurrect threads that are 6 years old