GameObjectExt.GetOrAddComponent<T> Method

Gets the Component of a given type. If it doesn’t exist, it is added to the GameObject.

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

Syntax

C#

public static T GetOrAddComponent<T>(
	this GameObject self
)
where T : Component

Parameters

 

self
Type: GameObject
Target GameObject where the component will be looked for and added to if it doesn’t exist

Type Parameters

 

T
Component type to get or add

Return Value

Type: T
Existing component or newly added if it didn’t exist before

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