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: https://issuetracker.unity3d.com/issues/getcomponentinparent-is-returning-null-when-the-gameobject-is-a-prefab

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

Syntax

C#

public static T SafeGetComponentInParent<T>(
	this Component self
)

Parameters

 

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

Type Parameters

 

T
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

Reference

ComponentExt Class
UltimateXR.Extensions.Unity Namespace