AddComponent
Adds a component to the game object and registers an undo operation for this action.
Read time 1 minuteLast updated 4 days ago
Definition
- Type: Method
- Namespace: UnityEditor
- Assembly: UnityEditor
AddComponent(GameObject, Type)
Adds a component to the game object and registers an undo operation for this action.
public static Component AddComponent(GameObject gameObject, Type type)
Parameters
The game object you want to add the component to.
The type of component you want to add.
Returns
Type | Description |
|---|---|
| Component | The newly added component. |
Remarks
If the undo is performed, the newly added component will be destroyed.
AddComponent<T>(GameObject)
Generic version.
public static T AddComponent<T>(GameObject gameObject) where T : Component
Parameters
The game object you want to add the component to.
Returns
Type | Description |
|---|---|
| T | The newly added component. |