T GetComponentInChildren( bool includeDisabled, bool includeSelf )

robot_2Generated
code_blocksInput

Description

Retrieves a component of type T from the current GameObject or any of its descendant GameObjects. This method allows you to specify whether to include components that are disabled and whether to include the current GameObject in the search.

Usage

Use this method when you need to find a specific component type within a GameObject hierarchy. You can control the search behavior using the includeDisabled and includeSelf parameters:

  • includeDisabled: Set to true to include components that are disabled in the search; otherwise, set to false.
  • includeSelf: Set to true to include the current GameObject in the search; otherwise, set to false.

Example

// Example of using GetComponentInChildren
var myComponent = myGameObject.GetComponentInChildren<MyComponentType>(includeDisabled: false, includeSelf: true);

if (myComponent != null)
{
    // Do something with the component
}