# GameObject

> Creates a new GameObject, with optional parameters to specify a name and set of components to attach.

## Definition

* **Type:** Constructor
* **Namespace:** [UnityEngine](/engine/6000.7/script-reference/unityengine.md)
* **Assembly:** UnityEngine.CoreModule

## GameObject(string)

Creates a new GameObject, with optional parameters to specify a name and set of components to attach.

```csharp
public GameObject(string name)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): The name of the [GameObject](/engine/6000.7/script-reference/unityengine/gameobject.md), specified as a string. The name is stored in the [name](/engine/6000.7/script-reference/unityengine/object/name.md) property of the GameObject.

### Remarks

Use the constructor with no arguments to create a GameObject with an empty `name` property and only a `Transform` component attached.

Use the constructor with `name` parameter to create a GameObject with the specified value as the name property and only a `Transform` component attached.

Use the constructor with `name` and `components` parameters to create a GameObject with the specified name and the specified components attached, in addition to the `Transform` component.

When you call the GameObject constructor from a MonoBehaviour script at runtime, the GameObject is created at the root of whichever scene is currently active at the time of the call to the constructor. The currently active scene is that returned by [SceneManager.GetActiveScene](/engine/6000.7/script-reference/unityengine/scenemanagement/scenemanager/getactivescene.md). The new GameObject is visible in the Hierarchy window at the root of this scene, meaning the GameObject has no parent by default.

If you call the constructor in a context where there is no valid scene loaded, such as during static initialization, or in scripts executing in Edit mode, the GameObject may be created in the "preview scene" or an internal context and not be part of any visible scene. In this case, you can explicitly add the GameObject to a scene using [SceneManager.MoveGameObjectToScene](/engine/6000.7/script-reference/unityengine/scenemanagement/scenemanager/movegameobjecttoscene.md).

### Examples

```csharp
using UnityEngine;

public class Example : MonoBehaviour
{
    private void Start()
    {
        GameObject exampleOne = new GameObject();
        exampleOne.name = "GameObject1";
        exampleOne.AddComponent<Rigidbody>();

        GameObject exampleTwo = new GameObject("GameObject2");
        exampleTwo.AddComponent<Rigidbody>();

        GameObject exampleThree = new GameObject("GameObject3", typeof(Rigidbody), typeof(BoxCollider));
    }
}
```

## GameObject()

Creates a new GameObject, with optional parameters to specify a name and set of components to attach.

```csharp
public GameObject()
```

### Remarks

Use the constructor with no arguments to create a GameObject with an empty `name` property and only a `Transform` component attached.

Use the constructor with `name` parameter to create a GameObject with the specified value as the name property and only a `Transform` component attached.

Use the constructor with `name` and `components` parameters to create a GameObject with the specified name and the specified components attached, in addition to the `Transform` component.

When you call the GameObject constructor from a MonoBehaviour script at runtime, the GameObject is created at the root of whichever scene is currently active at the time of the call to the constructor. The currently active scene is that returned by [SceneManager.GetActiveScene](/engine/6000.7/script-reference/unityengine/scenemanagement/scenemanager/getactivescene.md). The new GameObject is visible in the Hierarchy window at the root of this scene, meaning the GameObject has no parent by default.

If you call the constructor in a context where there is no valid scene loaded, such as during static initialization, or in scripts executing in Edit mode, the GameObject may be created in the "preview scene" or an internal context and not be part of any visible scene. In this case, you can explicitly add the GameObject to a scene using [SceneManager.MoveGameObjectToScene](/engine/6000.7/script-reference/unityengine/scenemanagement/scenemanager/movegameobjecttoscene.md).

### Examples

```csharp
using UnityEngine;

public class Example : MonoBehaviour
{
    private void Start()
    {
        GameObject exampleOne = new GameObject();
        exampleOne.name = "GameObject1";
        exampleOne.AddComponent<Rigidbody>();

        GameObject exampleTwo = new GameObject("GameObject2");
        exampleTwo.AddComponent<Rigidbody>();

        GameObject exampleThree = new GameObject("GameObject3", typeof(Rigidbody), typeof(BoxCollider));
    }
}
```

## GameObject(string, Type\[])

Creates a new GameObject, with optional parameters to specify a name and set of components to attach.

```csharp
public GameObject(string name, params Type[] components)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): The name of the [GameObject](/engine/6000.7/script-reference/unityengine/gameobject.md), specified as a string. The name is stored in the [name](/engine/6000.7/script-reference/unityengine/object/name.md) property of the GameObject.**** (\[Type\[]]\(https\://learn.microsoft.com/dotnet/api/system.type)): The components to attach, specified as an array of types that inherit from `Component`.

### Remarks

Use the constructor with no arguments to create a GameObject with an empty `name` property and only a `Transform` component attached.

Use the constructor with `name` parameter to create a GameObject with the specified value as the name property and only a `Transform` component attached.

Use the constructor with `name` and `components` parameters to create a GameObject with the specified name and the specified components attached, in addition to the `Transform` component.

When you call the GameObject constructor from a MonoBehaviour script at runtime, the GameObject is created at the root of whichever scene is currently active at the time of the call to the constructor. The currently active scene is that returned by [SceneManager.GetActiveScene](/engine/6000.7/script-reference/unityengine/scenemanagement/scenemanager/getactivescene.md). The new GameObject is visible in the Hierarchy window at the root of this scene, meaning the GameObject has no parent by default.

If you call the constructor in a context where there is no valid scene loaded, such as during static initialization, or in scripts executing in Edit mode, the GameObject may be created in the "preview scene" or an internal context and not be part of any visible scene. In this case, you can explicitly add the GameObject to a scene using [SceneManager.MoveGameObjectToScene](/engine/6000.7/script-reference/unityengine/scenemanagement/scenemanager/movegameobjecttoscene.md).

### Examples

```csharp
using UnityEngine;

public class Example : MonoBehaviour
{
    private void Start()
    {
        GameObject exampleOne = new GameObject();
        exampleOne.name = "GameObject1";
        exampleOne.AddComponent<Rigidbody>();

        GameObject exampleTwo = new GameObject("GameObject2");
        exampleTwo.AddComponent<Rigidbody>();

        GameObject exampleThree = new GameObject("GameObject3", typeof(Rigidbody), typeof(BoxCollider));
    }
}
```
