The GetComponents
method retrieves all components of a specified type T
attached to the current GameObject
. This method can optionally include components that are currently disabled.
The GetComponents
method retrieves all components of a specified type T
attached to the current GameObject
. This method can optionally include components that are currently disabled.
To use the GetComponents
method, call it on an instance of a Component
and specify whether you want to include disabled components in the results by passing a boolean value to the includeDisabled
parameter.
// Example of using GetComponents to retrieve all components of a specific type public class ExampleComponent : Component { public void PrintAllComponents() { // Retrieve all components of type ExampleComponent, including disabled ones var components = GetComponents<ExampleComponent>(true); foreach (var component in components) { // Perform operations with each component // For example, print the component's name Log.Info(component.GameObject.Name); } } }