TryGetComponent

TryGetComponent<T>(GameObject, out T)

public static bool TryGetComponent<T>(this GameObject gameObject, out T outComponent) ;

Description

Gets the component if it exists.

Type Parameters

Type Parameter Name Description Type Constraints
T Component type

Parameters

Parameter Name Description
gameObject GameObject
outComponent Output arguments of the found component

Returns

Returns true if the component is found.

TryGetComponent<T>(Component, out T)

public static bool TryGetComponent<T>(this Component component, out T outComponent) ;

Description

Gets the component if it exists.

Type Parameters

Type Parameter Name Description Type Constraints
T Component type

Parameters

Parameter Name Description
component Component
outComponent Output arguments of the found component

Returns

Returns true if the component is found.