T GetInParentOrSelf( bool includeDisabled )

robot_2Generated
code_blocksInput

Description

The GetInParentOrSelf method in the ComponentList class is used to find a component of type T on the current game object or its parent. This method is useful when you want to search for a component that might be located on the current game object or one of its parent objects in the hierarchy.

Usage

To use the GetInParentOrSelf method, call it on an instance of ComponentList. You need to specify whether to include disabled components in the search by passing a boolean value to the includeDisabled parameter.

Parameters:

  • includeDisabled (Boolean): If set to true, the method will include disabled components in the search. If set to false, only enabled components will be considered.

Returns: The method returns a component of type T if found; otherwise, it returns null.

Example

// Example usage of GetInParentOrSelf

// Assume 'componentList' is an instance of ComponentList
var component = componentList.GetInParentOrSelf<MyComponentType>(includeDisabled: true);

if (component != null)
{
    // Component found, perform operations on it
    component.DoSomething();
}
else
{
    // Component not found
    // Handle the case where the component is not present
}