Skip to content

Component Extension

Andrzej Kebab edited this page Feb 2, 2024 · 1 revision

UtilityLibrary.Unity.Runtime

CacheAllComponents<T>

Caches all components of type T in the specified Component. It searches for both fields and properties within the component, attempting to set their values based on the existing components in the GameObject's hierarchy.

scriptInstance.CacheAllComponents();

TryGetComponent<T>

Attempts to get the component of type T from the specified Component. Returns true if the component is found, otherwise false. The result is stored in the outComponent parameter.

bool success = scriptInstance.TryGetComponent(out T outComponent);

Parameters:

  • outComponent: The variable to store the result if the component is found.

Returns:

  • bool: true if the component is found, otherwise false.

TryGetComponentInParent<T>

Attempts to get the component of type T from the parent of the specified Component. Returns true if the component is found, otherwise false. The result is stored in the outComponent parameter.

bool success = scriptInstance.TryGetComponentInParent(out T outComponent);

Parameters:

  • outComponent: The variable to store the result if the component is found.

Returns:

  • bool: true if the component is found, otherwise false.

TryGetComponentInChildren<T>

Attempts to get the component of type T from the children of the specified Component. Returns true if the component is found, otherwise false. The result is stored in the outComponent parameter.

bool success = scriptInstance.TryGetComponentInChildren(out T outComponent);

Parameters:

  • outComponent: The variable to store the result if the component is found.

Returns:

  • bool: true if the component is found, otherwise false.

Clone this wiki locally