Search
 
SCRIPT & CODE EXAMPLE
 

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]);
            }
        }
    }
}

Comment

PREVIOUS NEXT
Code Example
Csharp :: c# yield 
Csharp :: C# round number of digits after decimal point 
Csharp :: mvc string format 
Csharp :: linked list reverse 
Csharp :: how to close another app in system with c# 
Csharp :: defualtsize UWP c# 
Csharp :: conditional if statement c# programming 
Csharp :: c# override gethashcode 
Csharp :: c# color to console color 
Csharp :: c# chunk array 
Csharp :: get device name c# console 
Csharp :: c# wpf row definition height * in code 
Csharp :: Oculus Unity button press 
Csharp :: Commenting on C# 
Csharp :: c# sum object values 
Csharp :: remove header visual studio android 
Csharp :: c# method returns multiple values 
Csharp :: winforms input box 
Csharp :: calculator in c# 
Csharp :: how to use buildcontext in initstate flutter 
Csharp :: combobox in datagrid wpf 
Csharp :: properties in c# 
Csharp :: Remove access to admin from deleting the file in C# 
Csharp :: c# instance class with ilogger 
Csharp :: indexof c# 
Csharp :: cdn providers 
Csharp :: top down view movement script 
Csharp :: number to character c# 
Csharp :: windows forms webbrowser refresh 
Csharp :: unity array c# 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =