The GetComponents<T>
method retrieves all components of type T
attached to the current GameObject
. This method can optionally include components that are currently disabled.
The GetComponents<T>
method retrieves all components of type T
attached to the current GameObject
. This method can optionally include components that are currently disabled.
To use the GetComponents<T>
method, specify the type of component you want to retrieve as the generic type parameter T
. Pass a boolean parameter includeDisabled
to indicate whether you want to include components that are disabled.
If includeDisabled
is set to true
, the method will return all components of type T
, regardless of their enabled state. If set to false
, only enabled components will be returned.
// Example of using GetComponents<T> to retrieve all components of a specific type public class ExampleComponent : Component { public void PrintAllComponents() { // Retrieve all components of type MyComponent, including disabled ones var components = GetComponents<MyComponent>(true); foreach (var component in components) { // Perform operations with each component component.DoSomething(); } } }