How To Find Inactive Gameobject in Unity

0
2180

We all are aware of that  GameObject.Find()  doesn’t find inactive gameobjects.

Win $200 in Bitcoins every hour!!

Things that can find inactive gameObjects :

  1. transform.Find() or transform.FindChild()
  2. transform.GetComponentsInChildren<Component>(true)
  3. Resources.FindObjectsOfTypeAll<Component>()
  1. Transform.Find() or Tranform.FindChild()

Finds a child gameobject ,both active and inactive .

            transform.Find (“InActiveGameObject_name”)

or

           transform.FindChild(“InActiveGameObject_name”)

If name contains a ‘/’ character it will traverse the hierarchy like a path name.

            transform.Find (“Child/InActive”)

  1. Transform.GetComponentsInChildren()

This also finds inactive gameobjects in child. If you want to include inactive child gameobjects  then  you must pass true as a parameter.

            transform.GetComponentsInChildren<Transform> (true)

This will find all the gameobjects with Transform component in child.

  1. Resources.FindObjectsOfTypeAll()

This will find all the gameobjects in the current scene , be it active or inactive.

           Resources.FindObjectsOfTypeAll<Transform>()

LEAVE A REPLY