Language
Edit

ComponentExtensions.EnsureComponent Method

Definition

Overloads

Name Description
EnsureComponent(GameObject, Type)

Ensure that a component of type exists on the game object.

EnsureComponent<T>(Component)

Ensure that a component of type T exists on the game object. If it doesn't exist, creates it.

EnsureComponent<T>(GameObject)

Ensure that a component of type T exists on the game object. If it doesn't exist, creates it.

EnsureComponent(GameObject, Type)

Ensure that a component of type exists on the game object.

public static UnityEngine.Component EnsureComponent(this UnityEngine.GameObject gameObject, Type component);
static member EnsureComponent : UnityEngine.GameObject * Type -> UnityEngine.Component
<Extension()>
Public Function EnsureComponent (gameObject As GameObject, component As Type) As Component

Parameters

gameObject
UnityEngine.GameObject

The game object to be searched or modified.

component
Type

A component on the game object for which a component of type should exist.

Returns

UnityEngine.Component

The component that was retrieved or created.

Remarks

If the given component type doesn't exist, the component is created on the give game object.

Applies to

EnsureComponent<T>(Component)

Ensure that a component of type T exists on the game object. If it doesn't exist, creates it.

public static T EnsureComponent<T>(this UnityEngine.Component component) where T : UnityEngine.Component;
static member EnsureComponent : UnityEngine.Component -> 'T (requires 'T :> UnityEngine.Component)
<Extension()>
Public Function EnsureComponent(Of T As Component) (component As Component) As T

Type Parameters

T

Type of the component.

Parameters

component
UnityEngine.Component

A component on the game object for which a component of type T should exist.

Returns

T

The component that was retrieved or created.

Applies to

EnsureComponent<T>(GameObject)

Ensure that a component of type T exists on the game object. If it doesn't exist, creates it.

public static T EnsureComponent<T>(this UnityEngine.GameObject gameObject) where T : UnityEngine.Component;
static member EnsureComponent : UnityEngine.GameObject -> 'T (requires 'T :> UnityEngine.Component)
<Extension()>
Public Function EnsureComponent(Of T As Component) (gameObject As GameObject) As T

Type Parameters

T

Type of the component.

Parameters

gameObject
UnityEngine.GameObject

Game object on which component should be.

Returns

T

The component that was retrieved or created.

Remarks

This extension has to remain in this class as it is required by the EnsureComponent<T>(Component) method

Applies to