T GetComponent( bool includeDisabled )

robot_2Generated
code_blocksInput

Description

The GetComponent<T> method retrieves a component of type T from the current GameObject to which this Component is attached. This method allows you to specify whether to include components that are currently disabled.

Usage

To use the GetComponent<T> method, call it on an instance of a Component or a derived class. Specify the type of component you want to retrieve as the generic type parameter T. Use the includeDisabled parameter to indicate whether you want to include components that are disabled in the search.

Example

// Example of using GetComponent<T> to retrieve a component
public class ExampleComponent : Component
{
    public void RetrieveComponent()
    {
        // Attempt to get a component of type MyComponent
        MyComponent myComponent = GetComponent<MyComponent>(includeDisabled: false);
        
        if (myComponent != null)
        {
            // Component found, perform operations on it
            myComponent.DoSomething();
        }
        else
        {
            // Component not found
            Log.Warning("MyComponent not found on this GameObject.");
        }
    }
}