Retrieves all components of type T
from the current GameObject
and its children. This method allows you to specify whether to include components that are disabled and whether to include the GameObject
itself in the search.
Retrieves all components of type T
from the current GameObject
and its children. This method allows you to specify whether to include components that are disabled and whether to include the GameObject
itself in the search.
Use this method when you need to gather all components of a specific type from a GameObject
and its descendants. This is particularly useful for operations that need to consider the entire hierarchy of objects, such as applying a function to all components of a certain type.
The method takes two parameters:
includeDisabled
: A bool
indicating whether to include components that are currently disabled.includeSelf
: A bool
indicating whether to include the GameObject
itself in the search.// Example usage of GetComponentsInChildren var gameObject = new GameObject(); // Retrieve all components of type MyComponent, including disabled ones, and include the GameObject itself var components = gameObject.GetComponentsInChildren<MyComponent>(includeDisabled: true, includeSelf: true); foreach (var component in components) { // Perform operations on each component component.DoSomething(); }