Documente Academic
Documente Profesional
Documente Cultură
Instantiate
Object.Instantiate
Other Versions
Parameters
original An existing object that you want to
make a copy of.
Returns
Object The instantiated clone.
Description
Clones the object original and returns the clone.
Search scripting...
This function makes a copy of an object in a similar wayunity3d.com
to the
Duplicate command in the editor. If you are cloning a GameObject
Manual Scripting API then you can also optionally specify its position and rotation (these
default to the original GameObject's position and rotation
otherwise). If you are cloning a Component then the GameObject it
Version: 2017.1 (switch to 2017.2b)
Scripting API C#
is attached to will also be cloned, again with an optional position
JS
and rotation.
UnityEngine SCRIPT LANGUAGE
When you clone a GameObject or Component, all child objects and
UnityEngine.Advertisements
Selectwith
components will also be cloned yourtheir
preferred scripting
properties setlanguage.
like thoseAll
UnityEngine.AI code snippets will be displayed in this
of the original object.
language.
UnityEngine.Analytics
U it E i A i ti
https://docs.unity3d.com/ScriptReference/Object.Instantiate.html 1/4
7/10/2017 Unity - Scripting API: Object.Instantiate
UnityEngine.Animations
By default the parent of the new object will be null, so it will not be
UnityEngine.Apple a "sibling" of the original. However, you can still set the parent
UnityEngine.Assertions using the overloaded methods. If a parent is speci ed and no
position and rotation is speci ed, the position and rotation of the
UnityEngine.Audio
original will be used for the cloned object's local position and
UnityEngine.CrashReportHandler
rotation, or its world position and rotation if the
UnityEngine.Events instantiateInWorldSpace parameter is true. If the position and
UnityEngine.EventSystems rotation is speci ed, they will be used as the object's position and
UnityEngine.Experimental rotation in world space.
UnityEngine.iOS
The active status of a GameObject at the time of cloning will be
UnityEngine.Networking passed on, so if the original is inactive then the clone will be
UnityEngine.Playables created in an inactive state too.
UnityEngine.Pro ling
See Also: In depth Prefab Instantiate discussion.
UnityEngine.Purchasing
UnityEngine.Rendering
UnityEngine.SceneManagement // Instantiates 10 copies of prefab each 2 units ap
UnityEngine.Scripting
using UnityEngine;
UnityEngine.Serialization using System.Collections;
UnityEngine.SocialPlatforms
UnityEngine.Sprites public class ExampleClass : MonoBehaviour
{
UnityEngine.TestTools
public Transform prefab;
UnityEngine.Timeline void Start()
UnityEngine.Tizen {
UnityEngine.U2D for (int i = 0; i < 10; i++)
{
Instantiate(prefab, new Vector3(i * 2.0
}
}
}
using UnityEngine;
using System.Collections;
Instantiate can also clone script instances directly. The entire game
object hierarchy will be cloned and the cloned script instance will
be returned.
https://docs.unity3d.com/ScriptReference/Object.Instantiate.html 2/4
7/10/2017 Unity - Scripting API: Object.Instantiate
using UnityEngine;
using System.Collections;
// ...other code...
}
void Update()
{
// Ctrl was pressed, launch a projectile
if (Input.GetButtonDown("Fire1"))
{
// Instantiate the projectile at the po
Missile clone = (Missile)Instantiate(pr
Parameters
original Object of type T that you want to make a clone of.
Returns
T Object of type T.
Description
You can also use Generics to instantiate objects. See the Generic
Functions page for more details.
https://docs.unity3d.com/ScriptReference/Object.Instantiate.html 3/4
7/10/2017 Unity - Scripting API: Object.Instantiate
using UnityEngine;
void Start()
{
Missile missileCopy = Instantiate<Missile>(
}
}
Leave Feedback
Is something described here not working as you expect it to? It might be a Known
2017-08-29.
Asset Store
https://docs.unity3d.com/ScriptReference/Object.Instantiate.html 4/4