# CreateGameObject

> Creates a new GameObject.

## Definition

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

## CreateGameObject(Scene, HideFlags, string, Type\[])

Creates a new GameObject.

```csharp
public static GameObject CreateGameObject(Scene scene, HideFlags hideFlags, string name, params Type[] types)
```

### Parameters

**** (\[Scene]\(/engine/6000.0/script-reference/unityengine/scenemanagement/scene)): Scene where the GameObject should be created.**** (\[HideFlags]\(/engine/6000.0/script-reference/unityengine/hideflags)): HideFlags to assign to the GameObject.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Name of the GameObject.**** (\[Type\[]]\(https\://learn.microsoft.com/dotnet/api/system.type)): The optional types to add to the GameObject when created.

### Returns

| Type                                                                    | Description                              |
| ----------------------------------------------------------------------- | ---------------------------------------- |
| [GameObject](/engine/6000.0/script-reference/unityengine/gameobject.md) | Returns the GameObject that was created. |

### Examples

```csharp
using UnityEngine;
using UnityEditor;

public class CreateComponentExample
{
    [MenuItem("ObjectFactoryExample/Create Camera GameObject")]
    public void CreateCameraEditor()
    {
        Selection.activeGameObject = ObjectFactory.CreateGameObject("Camera", typeof(Camera));
    }
}
```

## CreateGameObject(string, Type\[])

Creates a new GameObject.

```csharp
public static GameObject CreateGameObject(string name, params Type[] types)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Name of the GameObject.**** (\[Type\[]]\(https\://learn.microsoft.com/dotnet/api/system.type)): The optional types to add to the GameObject when created.

### Returns

| Type                                                                    | Description                              |
| ----------------------------------------------------------------------- | ---------------------------------------- |
| [GameObject](/engine/6000.0/script-reference/unityengine/gameobject.md) | Returns the GameObject that was created. |

### Examples

```csharp
using UnityEngine;
using UnityEditor;

public class CreateComponentExample
{
    [MenuItem("ObjectFactoryExample/Create Camera GameObject")]
    public void CreateCameraEditor()
    {
        Selection.activeGameObject = ObjectFactory.CreateGameObject("Camera", typeof(Camera));
    }
}
```
