Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

unity gameobject find inactive

FindObjectsOfType<T>(true)


Some examples:
//Inactive
{
	Rigidbody[] arr = GameObject.FindObjectsOfType<Rigidbody>();
}


//Active and Inactive
{
	Rigidbody[] arr = GameObject.FindObjectsOfType<Rigidbody>(true);
}

//Only Inactive
{
	//with "using System.Linq"
    {
    	Rigidbody[] arr = GameObject.FindObjectsOfType<Rigidbody>(true).Where(sr => !sr.gameObject.activeInHierarchy).ToArray();
    }
    
    //Without System.Linq
    {
    	Rigidbody[] allObjects = GameObject.FindObjectsOfType<Rigidbody>(true);
        List<Rigidbody> inactiveObjects = new List<Rigidbody>(allObjects.Length);

        for (int i = 0; i < allObjects.Length; i++)
        {
            if(!allObjects[i].gameobject.activeInHierarchy)
            {
                inactiveObjects.Add(allObjects[i]);
            }
        }
    }
}

 
PREVIOUS NEXT
Tagged: #unity #gameobject #find #inactive
ADD COMMENT
Topic
Name
1+7 =