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

book_4_sparkGenerated
code_blocksInput

Description

The GetComponentsInParent<T> method retrieves all components of type T from the current GameObject and its ancestor 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 component 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 results.
  • includeSelf (bool): If true, components from the current GameObject will be included in the results.

Example

// Example usage of GetComponentsInParent<T>
var components = myGameObject.GetComponentsInParent<MyComponentType>(includeDisabled: true, includeSelf: false);

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