T GetComponent( bool includeDisabled )

book_4_sparkGenerated
code_blocksInput

Description

Retrieves a component of type T from the GameObject. This method allows you to specify whether to include components that are currently disabled.

Usage

Use this method when you need to access a specific component attached to a GameObject. You can choose to include disabled components in the search by setting the includeDisabled parameter to true.

Example

// Example of using GetComponent to retrieve a component
var myComponent = myGameObject.GetComponent<MyComponentType>(includeDisabled: false);

if (myComponent != null)
{
    // Use the component
    myComponent.DoSomething();
}