How to find inactive objects using GameObject.Find(" ") in Unity3D?

Well, using GameObject.Find(...) will never return any inactive objects. As the documentation states:

This function only returns active gameobjects.

Even if you could, you'd want to keep these costly calls to a minimum.

There are "tricks" to finding inactive GameObjects, such as using a Resources.FindObjectsOfTypeAll(Type type) call (though that should be used with extreme caution).

But your best bet is writing your own management code. This can be a simple class holding a list of objects that you might want to find and use at some point. You can put your object into it on first load. Or perhaps add/remove them on becoming active or inactive. Whatever your particular scenario needs.


Since Unity 2020

In the years since this question was asked, Unity put in the exact thing you need. At least, the exact thing I needed. Posting here for future peoples.

To find an object of a certain type whether it's on an active or inactive GameObject, you can use FindObjectsOfType<T>(true)

Objects attached to inactive GameObjects are only included if inactiveObjects is set to true.

Therefore, just use it like you regularly would, but also pass in true.

The following code requires System.Linq:

SpriteRenderer[] onlyActive = GameObject.FindObjectsOfType<SpriteRenderer>();

SpriteRenderer[] activeAndInactive = GameObject.FindObjectsOfType<SpriteRenderer>(true);

// requires "using System.Linq;"
SpriteRenderer[] onlyInactive = GameObject.FindObjectsOfType<SpriteRenderer>(true).Where(sr => !sr.gameObject.activeInHierarchy).ToArray();

The first array includes only SpriteRenderers on active GameObjects, the second includes both those on active and inactive GameObjects, and the third uses System.Linq to only include those on inactive GameObjects.


If you have parent object (just empty object that plays role of a folder) you can find active and inactive objects like this:

this.playButton = MainMenuItems.transform.Find("PlayButton").gameObject;

MainMenuItems - is your parent object.

Please note that Find() is slow method, so consider using references to objects or organize Dictionary collections with gameobjects you need access very often

Good luck!