ComponentExt.SafeGetComponentInParent<T> Method

Gets the Component of a given type in the GameObject or any of its parents. It also works on prefabs, where regular GetComponentInParent(Type, Boolean) will not work:

Namespace: UltimateXR.Extensions.Unity
Assembly: UltimateXR (in UltimateXR.dll) Version:



public static T SafeGetComponentInParent<T>(
	this Component self



Type: Component
[Missing documentation for “M:UltimateXR.Extensions.Unity.ComponentExt.SafeGetComponentInParent``1(UnityEngine.Component)”]

Type Parameters


Component type to get

Return Value

Type: T
Component in same GameObject or any of its parents. Null if it wasn’t found

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type Component. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

See Also


ComponentExt Class
UltimateXR.Extensions.Unity Namespace