# AddComponent

> Adds a component to the game object and registers an undo operation for this action.

## Definition

* **Type:** Method
* **Namespace:** [UnityEditor](/engine/6000.0/script-reference/unityeditor.md)
* **Assembly:** UnityEditor

## AddComponent(GameObject, Type)

Adds a component to the game object and registers an undo operation for this action.

```csharp
public static Component AddComponent(GameObject gameObject, Type type)
```

### Parameters

**** (\[GameObject]\(/engine/6000.0/script-reference/unityengine/gameobject)): The game object you want to add the component to.**** (\[Type]\(https\://learn.microsoft.com/dotnet/api/system.type)): The type of component you want to add.

### Returns

| Type                                                                  | Description                |
| --------------------------------------------------------------------- | -------------------------- |
| [Component](/engine/6000.0/script-reference/unityengine/component.md) | The newly added component. |

### Remarks

If the undo is performed, the newly added component will be destroyed.

## AddComponent\<T>(GameObject)

Generic version.

```csharp
public static T AddComponent<T>(GameObject gameObject) where T : Component
```

### Parameters

**** (\[GameObject]\(/engine/6000.0/script-reference/unityengine/gameobject)): The game object you want to add the component to.

### Returns

| Type | Description                |
| ---- | -------------------------- |
| T    | The newly added component. |
