GameObjectExt.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 GameObject self
)

Parameters

 

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

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 GameObject. 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

GameObjectExt Class
UltimateXR.Extensions.Unity Namespace