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

book_4_sparkGenerated
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 this 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 current GameObject in the search.

Parameters:

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

Example

// Example of using GetComponentsInChildren to retrieve all MeshRenderer components
GameObject myGameObject = new GameObject();
IEnumerable<MeshRenderer> meshRenderers = myGameObject.GetComponentsInChildren<MeshRenderer>(includeDisabled: true, includeSelf: true);

foreach (var renderer in meshRenderers)
{
    // Perform operations with each MeshRenderer
}