The GetComponents<T>
method retrieves all components of type T
attached to this GameObject
. This method can optionally include components that are currently disabled.
The GetComponents<T>
method retrieves all components of type T
attached to this GameObject
. This method can optionally include components that are currently disabled.
Use this method when you need to access multiple components of a specific type on a GameObject
. You can specify whether to include disabled components by passing a boolean value to the includeDisabled
parameter.
// 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 with each component component.DoSomething(); }