The GetComponents<T>
method retrieves all components of type T
attached to the GameObject
. This method can include components that are currently disabled, based on the includeDisabled
parameter.
The GetComponents<T>
method retrieves all components of type T
attached to the GameObject
. This method can include components that are currently disabled, based on the includeDisabled
parameter.
Use this method when you need to access multiple components of a specific type on a GameObject
. The method returns an IEnumerable<T>
, allowing you to iterate over the components.
Set the includeDisabled
parameter to true
if you want to include components that are disabled in the result. Set it to false
to only include enabled components.
// Example of using GetComponents to retrieve all components of a specific type var gameObject = new GameObject(); // Retrieve all components of type MyComponent, including disabled ones var components = gameObject.GetComponents<MyComponent>(true); foreach (var component in components) { // Perform operations on each component component.DoSomething(); }