# Instantiate

> Clones the object original and sets the position and rotation of the clone.

## Definition

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

## Instantiate(Object, Vector3, Quaternion)

Clones the object `original` and sets the position and rotation of the clone.

```csharp
public static Object Instantiate(Object original, Vector3 position, Quaternion rotation)
```

### Parameters

**** (\[Object]\(/engine/6000.6/script-reference/unityengine/object)): An existing object that you want to make a copy of.**** (\[Vector3]\(/engine/6000.6/script-reference/unityengine/vector3)): The position for the new object, in world space.**** (\[Quaternion]\(/engine/6000.6/script-reference/unityengine/quaternion)): The orientation of the new object.

### Returns

| Type                                                            | Description             |
| --------------------------------------------------------------- | ----------------------- |
| [Object](/engine/6000.6/script-reference/unityengine/object.md) | The instantiated clone. |

### Remarks

Unity uses the `position` and `rotation` that you specify as the clone's position and rotation in world space. The new object has no parent.

You can use this method to create new objects at runtime, such as projectiles or particle systems for explosion effects.

```csharp
using UnityEngine;

// Instantiate a rigidbody then set the velocity

public class Example : MonoBehaviour
{
    // Assign a Rigidbody component in the inspector to instantiate

    public Rigidbody projectile;

    void Update()
    {
        // Ctrl was pressed, launch a projectile
        if (Input.GetButtonDown("Fire1"))
        {
            // Instantiate the projectile at the position and rotation of this transform
            Rigidbody clone;
            clone = Instantiate(projectile, transform.position, transform.rotation);

            // Give the cloned object an initial velocity along the current
            // object's Z axis
            clone.velocity = transform.TransformDirection(Vector3.forward * 10);
        }
    }
}
```

You can also use this method to clone script instances directly. Unity clones the entire [GameObject](/engine/6000.6/script-reference/unityengine/gameobject.md) hierarchy and returns the cloned script instance.

```csharp
using UnityEngine;
using System.Collections;

public class Missile : MonoBehaviour
{
    public int timeoutDestructor;

    // ...other code...
}


public class ExampleClass : MonoBehaviour
{
    // Instantiate a Prefab with an attached Missile script
    public Missile projectile;

    void Update()
    {
        // Ctrl was pressed, launch a projectile
        if (Input.GetButtonDown("Fire1"))
        {
            // Instantiate the projectile at the position and rotation of this transform
            Missile clone = Instantiate(projectile, transform.position, transform.rotation);

            // Set the missiles timeout destructor to 5
            clone.timeoutDestructor = 5;
        }
    }
}
```

You can also instantiate multiple clones at different positions.

```csharp
// Instantiates 10 copies of Prefab each 2 units apart from each other

using UnityEngine;

public class Example : MonoBehaviour
{
    public GameObject prefab;
    void Start()
    {
        for (var i = 0; i < 10; i++)
        {
            Instantiate(prefab, new Vector3(i * 2.0f, 0, 0), Quaternion.identity);
        }
    }
}
```

## Instantiate(Object, Vector3, Quaternion, Transform)

Clones the object `original`, sets the position and rotation of the clone, and sets `parent` as the parent of the clone.

```csharp
public static Object Instantiate(Object original, Vector3 position, Quaternion rotation, Transform parent)
```

### Parameters

**** (\[Object]\(/engine/6000.6/script-reference/unityengine/object)): An existing object that you want to make a copy of.**** (\[Vector3]\(/engine/6000.6/script-reference/unityengine/vector3)): The position for the new object, in world space.**** (\[Quaternion]\(/engine/6000.6/script-reference/unityengine/quaternion)): The orientation of the new object.**** (\[Transform]\(/engine/6000.6/script-reference/unityengine/transform)): The [Transform](/engine/6000.6/script-reference/unityengine/transform.md) to set as the parent of the new object.

### Returns

| Type                                                            | Description             |
| --------------------------------------------------------------- | ----------------------- |
| [Object](/engine/6000.6/script-reference/unityengine/object.md) | The instantiated clone. |

### Remarks

Unity uses the `position` and `rotation` that you specify as the clone's position and rotation in world space, and sets `parent` as the parent of the clone.

## Instantiate(Object)

Clones the object `original` and returns the clone.

```csharp
public static Object Instantiate(Object original)
```

### Parameters

**** (\[Object]\(/engine/6000.6/script-reference/unityengine/object)): An existing object that you want to make a copy of.

### Returns

| Type                                                            | Description             |
| --------------------------------------------------------------- | ----------------------- |
| [Object](/engine/6000.6/script-reference/unityengine/object.md) | The instantiated clone. |

### Remarks

This method makes a copy of an object, similar to the **Duplicate** command in the Editor.

When you clone a [GameObject](/engine/6000.6/script-reference/unityengine/gameobject.md) or [Component](/engine/6000.6/script-reference/unityengine/component.md), Unity also clones all of its child objects and components, and sets their properties to match the original. If you clone a [Component](/engine/6000.6/script-reference/unityengine/component.md), Unity also clones the [GameObject](/engine/6000.6/script-reference/unityengine/gameobject.md) that the component is attached to.

This overload doesn't set a position, rotation, or parent for the clone. By default, the new object has no parent, even if `original` has one. To set a position, rotation, or parent, use one of the other overloads, or an overload that takes an [InstantiateParameters](/engine/6000.6/script-reference/unityengine/instantiateparameters.md) struct to pass any combination of these values.

The clone keeps the active state of the original, so if `original` is inactive, the clone is also inactive. For the clone and each object in its hierarchy, Unity calls the `Awake` and `OnEnable` methods on a [MonoBehaviour](/engine/6000.6/script-reference/unityengine/monobehaviour.md) or [Component](/engine/6000.6/script-reference/unityengine/component.md) only if it's active in the hierarchy when you call this method.

**Note:** When this method clones a child object, it also clones that child's own children. To prevent a stack overflow, Unity limits this nested cloning. If the cloning exceeds more than half of the stack size, Unity throws an `InsufficientExecutionStackException`.

This method doesn't create a prefab connection to the new object. To create an object with a prefab connection, use [PrefabUtility.InstantiatePrefab](/engine/6000.6/script-reference/unityeditor/prefabutility/instantiateprefab.md) instead.

Additional Resources:

[Instantiating prefabs at run time](/engine/6000.6/manual/working-with-gameobjects/prefabs/instantiating.md)

[PrefabUtility.InstantiatePrefab](/engine/6000.6/script-reference/unityeditor/prefabutility/instantiateprefab.md).

## Instantiate(Object, Scene)

Clones the object `original` and adds the clone to the specified scene.

```csharp
public static Object Instantiate(Object original, Scene scene)
```

### Parameters

**** (\[Object]\(/engine/6000.6/script-reference/unityengine/object)): An existing object that you want to make a copy of.**** (\[Scene]\(/engine/6000.6/script-reference/unityengine/scenemanagement/scene)): The scene to add the new object to.

### Returns

| Type                                                            | Description             |
| --------------------------------------------------------------- | ----------------------- |
| [Object](/engine/6000.6/script-reference/unityengine/object.md) | The instantiated clone. |

### Remarks

This overload adds the clone to a specific loaded scene instead of the active scene.

## Instantiate\<T>(T, InstantiateParameters)

Clones the object of type T using the settings in `parameters`, and returns the clone.

```csharp
public static T Instantiate<T>(T original, InstantiateParameters parameters) where T : Object
```

### Parameters

**** (T): Object of type T that you want to clone.**** (\[InstantiateParameters]\(/engine/6000.6/script-reference/unityengine/instantiateparameters)): An [InstantiateParameters](/engine/6000.6/script-reference/unityengine/instantiateparameters.md) struct that specifies options for the new object, such as its parent, the scene to add it to, and whether to use world space.

### Returns

| Type | Description                               |
| ---- | ----------------------------------------- |
| T    | The instantiated cloned object of type T. |

## Instantiate\<T>(T, Vector3, Quaternion, InstantiateParameters)

Clones the object of type T, sets the position and rotation of the clone, and applies the settings in `parameters`.

```csharp
public static T Instantiate<T>(T original, Vector3 position, Quaternion rotation, InstantiateParameters parameters) where T : Object
```

### Parameters

**** (T): Object of type T that you want to clone.**** (\[Vector3]\(/engine/6000.6/script-reference/unityengine/vector3)): The position for the new object, in world space.**** (\[Quaternion]\(/engine/6000.6/script-reference/unityengine/quaternion)): The orientation of the new object.**** (\[InstantiateParameters]\(/engine/6000.6/script-reference/unityengine/instantiateparameters)): An [InstantiateParameters](/engine/6000.6/script-reference/unityengine/instantiateparameters.md) struct that specifies options for the new object, such as its parent, the scene to add it to, and whether to use world space.

### Returns

| Type | Description                               |
| ---- | ----------------------------------------- |
| T    | The instantiated cloned object of type T. |

## Instantiate(Object, Transform)

Clones the object `original` and sets `parent` as the parent of the clone.

```csharp
public static Object Instantiate(Object original, Transform parent)
```

### Parameters

**** (\[Object]\(/engine/6000.6/script-reference/unityengine/object)): An existing object that you want to make a copy of.**** (\[Transform]\(/engine/6000.6/script-reference/unityengine/transform)): The [Transform](/engine/6000.6/script-reference/unityengine/transform.md) to set as the parent of the new object.

### Returns

| Type                                                            | Description             |
| --------------------------------------------------------------- | ----------------------- |
| [Object](/engine/6000.6/script-reference/unityengine/object.md) | The instantiated clone. |

### Remarks

This overload sets a parent for the clone but doesn't set a position or rotation. Unity uses the existing object's position and rotation as the clone's local position and rotation, relative to `parent`.

To keep the existing object's world position and rotation instead, use [Object.Instantiate(Object, Transform, bool)](/engine/6000.6/script-reference/unityengine/object/instantiate.md#instantiate\(object-transform-bool\)) and set `instantiateInWorldSpace` to true.

## Instantiate(Object, Transform, bool)

Clones the object `original`, sets `parent` as the parent of the clone, and sets whether the clone keeps its local or world position.

```csharp
public static Object Instantiate(Object original, Transform parent, bool instantiateInWorldSpace)
```

### Parameters

**** (\[Object]\(/engine/6000.6/script-reference/unityengine/object)): An existing object that you want to make a copy of.**** (\[Transform]\(/engine/6000.6/script-reference/unityengine/transform)): The [Transform](/engine/6000.6/script-reference/unityengine/transform.md) to set as the parent of the new object.**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): Set to true to keep the new object's world position and rotation. Set to false to position the new object relative to `parent`.

### Returns

| Type                                                            | Description             |
| --------------------------------------------------------------- | ----------------------- |
| [Object](/engine/6000.6/script-reference/unityengine/object.md) | The instantiated clone. |

### Remarks

If `instantiateInWorldSpace` is false, Unity uses the existing object's position and rotation as the clone's local position and rotation, relative to `parent`. If `instantiateInWorldSpace` is true, Unity keeps the existing object's world position and rotation.

The following example instantiates a prefab as a child of another [GameObject](/engine/6000.6/script-reference/unityengine/gameobject.md), first keeping the prefab's local position relative to the parent, then keeping its original world position.

### Examples

```csharp
using UnityEngine;

// Instantiate a Prefab as a child of another object.

public class Example : MonoBehaviour
{
    // Assign a Prefab in the Inspector.
    public GameObject prefab;

    // Assign the Transform to use as the parent in the Inspector.
    public Transform parent;

    void Start()
    {
        // Instantiate the Prefab as a child of parent.
        // The clone keeps its local position and rotation relative to parent.
        Instantiate(prefab, parent);

        // Pass true for instantiateInWorldSpace to keep the Prefab's
        // original world position and rotation instead.
        Instantiate(prefab, parent, true);
    }
}
```

## Instantiate\<T>(T)

Clones the object of type T and returns the clone.

```csharp
public static T Instantiate<T>(T original) where T : Object
```

### Parameters

**** (T): Object of type T that you want to clone.

### Returns

| Type | Description                               |
| ---- | ----------------------------------------- |
| T    | The instantiated cloned object of type T. |

### Remarks

You can use generic types to instantiate objects so you don't have to cast the result to a specific type. For more information on generics in C#, refer to Microsoft's [Generic methods](https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/generics/generic-methods) documentation.

### Examples

```csharp
using UnityEngine;

public class Missile : MonoBehaviour
{
    // ...other code...
}

public class InstantiateGenericsExample : MonoBehaviour
{
    public Missile missile;

    void Start()
    {
        Missile missileCopy = Instantiate<Missile>(missile);
    }
}
```

## Instantiate\<T>(T, Vector3, Quaternion)

Clones the object of type T and sets the position and rotation of the clone.

```csharp
public static T Instantiate<T>(T original, Vector3 position, Quaternion rotation) where T : Object
```

### Parameters

**** (T): Object of type T that you want to clone.**** (\[Vector3]\(/engine/6000.6/script-reference/unityengine/vector3)): The position for the new object, in world space.**** (\[Quaternion]\(/engine/6000.6/script-reference/unityengine/quaternion)): The orientation of the new object.

### Returns

| Type | Description                               |
| ---- | ----------------------------------------- |
| T    | The instantiated cloned object of type T. |

## Instantiate\<T>(T, Vector3, Quaternion, Transform)

Clones the object of type T, sets the position and rotation of the clone, and sets `parent` as the parent of the clone.

```csharp
public static T Instantiate<T>(T original, Vector3 position, Quaternion rotation, Transform parent) where T : Object
```

### Parameters

**** (T): Object of type T that you want to clone.**** (\[Vector3]\(/engine/6000.6/script-reference/unityengine/vector3)): The position for the new object, in world space.**** (\[Quaternion]\(/engine/6000.6/script-reference/unityengine/quaternion)): The orientation of the new object.**** (\[Transform]\(/engine/6000.6/script-reference/unityengine/transform)): The [Transform](/engine/6000.6/script-reference/unityengine/transform.md) to set as the parent of the new object.

### Returns

| Type | Description                               |
| ---- | ----------------------------------------- |
| T    | The instantiated cloned object of type T. |

## Instantiate\<T>(T, Transform)

Clones the object of type T and sets `parent` as the parent of the clone.

```csharp
public static T Instantiate<T>(T original, Transform parent) where T : Object
```

### Parameters

**** (T): Object of type T that you want to clone.**** (\[Transform]\(/engine/6000.6/script-reference/unityengine/transform)): The [Transform](/engine/6000.6/script-reference/unityengine/transform.md) to set as the parent of the new object.

### Returns

| Type | Description                               |
| ---- | ----------------------------------------- |
| T    | The instantiated cloned object of type T. |

## Instantiate\<T>(T, Transform, bool)

Clones the object of type T, sets `parent` as the parent of the clone, and sets whether the clone keeps its local or world position.

```csharp
public static T Instantiate<T>(T original, Transform parent, bool worldPositionStays) where T : Object
```

### Parameters

**** (T): Object of type T that you want to clone.**** (\[Transform]\(/engine/6000.6/script-reference/unityengine/transform)): The [Transform](/engine/6000.6/script-reference/unityengine/transform.md) to set as the parent of the new object.**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): Set to true to keep the new object's world position and rotation. Set to false to position the new object relative to `parent`.

### Returns

| Type | Description                               |
| ---- | ----------------------------------------- |
| T    | The instantiated cloned object of type T. |
