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, call it on an instance of a Component
or a derived class. Specify the type of component you want to retrieve as the generic type parameter T
. Use the includeDisabled
parameter to determine whether to include components that are not currently enabled.
// 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); } } }