# CreateGameObject

> Creates a new GameObject with the specified name and components, in a specific scene and with hide flags.

## Definition

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

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

Creates a new GameObject with the specified name and components, in a specific scene and with hide flags.

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

### Parameters

**** (\[Scene]\(/engine/7000.0/script-reference/unityengine/scenemanagement/scene)): The scene to create the GameObject in.**** (\[HideFlags]\(/engine/7000.0/script-reference/unityengine/hideflags)): The hide flags to assign to the GameObject.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): The name of the new GameObject.**** (\[Type\[]]\(https\://learn.microsoft.com/dotnet/api/system.type)): The types of the components to add to the new GameObject.

### Returns

| Type                                                                    | Description                             |
| ----------------------------------------------------------------------- | --------------------------------------- |
| [GameObject](/engine/7000.0/script-reference/unityengine/gameobject.md) | The GameObject that the method created. |

### Remarks

The method throws an exception if `scene` isn't valid.

## CreateGameObject(string, Type\[])

Creates a new GameObject with the specified name and components.

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

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): The name of the new GameObject.**** (\[Type\[]]\(https\://learn.microsoft.com/dotnet/api/system.type)): The types of the components to add to the new GameObject.

### Returns

| Type                                                                    | Description                             |
| ----------------------------------------------------------------------- | --------------------------------------- |
| [GameObject](/engine/7000.0/script-reference/unityengine/gameobject.md) | The GameObject that the method created. |

### Remarks

The method adds the components while the GameObject is inactive, then activates it and gives it the default parent for new objects. To create the GameObject in a specific scene, use the overload that takes a [Scene](/engine/7000.0/script-reference/unityengine/scenemanagement/scene.md).

### Examples

```csharp
using UnityEngine;
using UnityEditor;

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