# DuplicateGameObject

> Duplicates a single GameObject and returns the new GameObject.

## Definition

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

## DuplicateGameObject(GameObject)

Duplicates a single GameObject and returns the new GameObject.

```csharp
public static GameObject DuplicateGameObject(GameObject gameObject)
```

### Parameters

**** (\[GameObject]\(/engine/6000.7/script-reference/unityengine/gameobject)): The GameObject to be duplicated.

### Returns

| Type                                                                    | Description                |
| ----------------------------------------------------------------------- | -------------------------- |
| [GameObject](/engine/6000.7/script-reference/unityengine/gameobject.md) | The duplicated GameObject. |

### Remarks

Duplicates a GameObject within a Scene. The duplicated GameObject will be on the same level in the hierarchy as the original GameObject, and they will share the same parent. If there are any children or components that belong to the original GameObject, the duplicate will have them as well.

For duplicating more than one GameObject use [GameObjectUtility.DuplicateGameObjects](/engine/6000.7/script-reference/unityeditor/gameobjectutility/duplicategameobjects.md). For duplicating Assets use CopyAsset.

```csharp
using UnityEngine;
using UnityEditor;

public static class DuplicateGameObjectExample
{
    // Create context menu
    [MenuItem("Example/DuplicateGameObject")]
    public static void DuplicateTest()
    {
        // The original GameObject
        GameObject gameObject = new GameObject();

        // The duplicated GameObject
        GameObject duplicatedGameObject = GameObjectUtility.DuplicateGameObject(gameObject);

        // Display the names of the original and duplicated GameObjects in the console
        Debug.Log("The original GameObject: " + gameObject.name);
        Debug.Log("The duplicated GameObject: " + duplicatedGameObject.name);
    }
}
```

Any errors and warnings from the duplication operation are reported in the log and the console.

## DuplicateGameObject(GameObject, bool)

Duplicates a single GameObject and returns the new GameObject.

```csharp
public static GameObject DuplicateGameObject(GameObject gameObject, bool recordUndo)
```

### Parameters

**** (\[GameObject]\(/engine/6000.7/script-reference/unityengine/gameobject)): The GameObject to be duplicated.**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): If true, the user will be able to Undo this action.

### Returns

| Type                                                                    | Description                |
| ----------------------------------------------------------------------- | -------------------------- |
| [GameObject](/engine/6000.7/script-reference/unityengine/gameobject.md) | The duplicated GameObject. |

### Remarks

Duplicates a GameObject within a Scene. The duplicated GameObject will be on the same level in the hierarchy as the original GameObject, and they will share the same parent. If there are any children or components that belong to the original GameObject, the duplicate will have them as well.

For duplicating more than one GameObject use [GameObjectUtility.DuplicateGameObjects](/engine/6000.7/script-reference/unityeditor/gameobjectutility/duplicategameobjects.md). For duplicating Assets use CopyAsset.

```csharp
using UnityEngine;
using UnityEditor;

public static class DuplicateGameObjectExample
{
    // Create context menu
    [MenuItem("Example/DuplicateGameObject")]
    public static void DuplicateTest()
    {
        // The original GameObject
        GameObject gameObject = new GameObject();

        // The duplicated GameObject
        GameObject duplicatedGameObject = GameObjectUtility.DuplicateGameObject(gameObject);

        // Display the names of the original and duplicated GameObjects in the console
        Debug.Log("The original GameObject: " + gameObject.name);
        Debug.Log("The duplicated GameObject: " + duplicatedGameObject.name);
    }
}
```

Any errors and warnings from the duplication operation are reported in the log and the console.
