IEnumerable<T> GetComponentsInChildren( bool includeDisabled, bool includeSelf )

robot_2Generated
code_blocksInput

Description

The GetComponentsInChildren method retrieves all components of a specified type T from the current GameObject and its descendant GameObjects. This method allows you to specify whether to include components from disabled GameObjects and whether to include the components from the current GameObject itself.

Usage

To use the GetComponentsInChildren method, call it on a GameObject instance, specifying the type of components you want to retrieve. You can also specify whether to include components from disabled GameObjects and whether to include the components from the current GameObject itself.

Parameters:

  • includeDisabled (Boolean): If true, components from disabled GameObjects will be included in the result.
  • includeSelf (Boolean): If true, components from the current GameObject will be included in the result.

Example

// Example of using GetComponentsInChildren
var gameObject = new GameObject();

// Retrieve all components of type MyComponent from the GameObject and its children
var components = gameObject.GetComponentsInChildren<MyComponent>(includeDisabled: true, includeSelf: true);

foreach (var component in components)
{
    // Perform operations with each component
    component.DoSomething();
}