ComponentExt.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 Component self
)
where T : Component

Parameters

 

self
Type: Component
Component whose GameObject will be used to retrieve or add the given component type to

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