---
tags:
    - "Create"
    - "New"
---

# Instantiate

[Game Object](../index.md) / [Creation](index.md) / **Instantiate**

## Description

Creates a new instance of the template game object at the specified location

## Parameters

| Name | Description |
| :--- | :---------- |
| Game Object | The template game object that makes a copy |
| Position | The position of the new game object |
| Rotation | The orientation of the new game object |
| Parent | An optional parent object of the new instance |
| Set | An optional location where to save the new instance |

## Code

```cs
using System;
using UnityEngine;
using VisualScript.Icons;

namespace VisualScript.Runtime
{
    [Title("Instantiate")]
    [Image(typeof(IconCubeSolid), ColorTheme.Type.TextLight)]
    
    [Description("Creates a new instance of the template game object at the specified location")]
    [Category("Game Object/Creation/Instantiate")]
    
    [Parameter("Game Object", "The template game object that makes a copy")]
    [Parameter("Position", "The position of the new game object")]
    [Parameter("Rotation", "The orientation of the new game object")]
    [Parameter("Parent", "An optional parent object of the new instance")]
    [Parameter("Set", "An optional location where to save the new instance")]
    
    [Keywords("Create", "New")]
    
    [Serializable]
    public class InstructionCoreGameObjectInstantiate : Instruction
    {
        [SerializeField] private GetGameObject m_GameObject = new GetGameObject(
            new TypeGameObjectPrefab()
        );

        [SerializeField] private GetVector3 m_Position = new GetVector3();
        [SerializeField] private GetQuaternion m_Rotation = new GetQuaternion();
        [SerializeField] private GetGameObject m_Parent = new GetGameObject();

        [SerializeField] private SetGameObject m_Set = new SetGameObject(
            new TypeGameObjectNoneSet()
        );

        protected override string GetTitle(GameObject source) => $"Instantiate {this.m_GameObject}";

        protected override Awaitable Run(Args args)
        {
            GameObject gameObject = this.m_GameObject.Get(args);
            if (gameObject == null) return Done;

            GameObject instance = UnityEngine.Object.Instantiate(
                gameObject,
                this.m_Position.Get(args),
                this.m_Rotation.Get(args),
                this.m_Parent.Get<Transform>(args)
            );

            if (instance != null)
            {
                this.m_Set.Set(instance, args);
            }
            
            return Done;
        }
    }
}
```

