ComponentExtensions.EnsureComponent Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
EnsureComponent(GameObject, Type) |
Ensure that a component of type exists on the game object. If it doesn't exist, creates it. |
EnsureComponent<T>(Component) |
Ensure that a component of type |
EnsureComponent<T>(GameObject) |
Ensure that a component of type |
EnsureComponent(GameObject, Type)
Ensure that a component of type exists on the game object. If it doesn't exist, creates it.
public:
[System::Runtime::CompilerServices::Extension]
static UnityEngine::Component ^ EnsureComponent(UnityEngine::GameObject ^ gameObject, Type ^ component);
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
- component
- Type
A component on the game object for which a component of type should exist.
Returns
The component that was retrieved or created.
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:
generic <typename T>
where T : UnityEngine::Component[System::Runtime::CompilerServices::Extension]
static T EnsureComponent(UnityEngine::Component ^ component);
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
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:
generic <typename T>
where T : UnityEngine::Component[System::Runtime::CompilerServices::Extension]
static T EnsureComponent(UnityEngine::GameObject ^ gameObject);
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
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