Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


InstantiateAsync

Captures a snapshot of the original object that's related to another GameObject and obtains an AsyncInstantiateOperation instance of the resulting objects.
Read time 12 minutesLast updated 4 days ago

Definition

  • Type: Method
  • Namespace: UnityEngine
  • Assembly: UnityEngine.CoreModule

InstantiateAsync<T>(T)

Captures a snapshot of the original object that's related to another GameObject and obtains an AsyncInstantiateOperation instance of the resulting objects.
public static AsyncInstantiateOperation<T> InstantiateAsync<T>(T original) where T : Object

Parameters

original

T
An existing object that you want to make a copy of.

Returns

Type

Description

AsyncInstantiateOperation<T>An asynchronous operation that contains the resulting objects.

Remarks

The operation is mainly asynchronous, but the last stage involving integration and awake calls is executed on the main thread. The operation can be cancelled, or the integration stage can be delayed using allowSceneActivation.
It is possible to yield a return operation or call its WaitForCompletion() method to finish the operation in a synchronized way.
For extra control you can use the overrides that take an InstantiateParameters struct. This includes extra options like deciding between using local or world space, or to specify a target scene for the objects.

InstantiateAsync<T>(T, Transform)

Clones the object of type T asynchronously, sets
parent
as the parent of the clone, and returns an
AsyncInstantiateOperation
.
public static AsyncInstantiateOperation<T> InstantiateAsync<T>(T original, Transform parent) where T : Object

Parameters

original

T
An existing object that you want to make a copy of.

parent

The Transform to set as the parent of the new object.

Returns

Type

Description

AsyncInstantiateOperation<T>An asynchronous operation that contains the resulting objects.

InstantiateAsync<T>(T, Vector3, Quaternion)

Clones the object of type T asynchronously, sets the position and rotation of the clone, and returns an
AsyncInstantiateOperation
.
public static AsyncInstantiateOperation<T> InstantiateAsync<T>(T original, Vector3 position, Quaternion rotation) where T : Object

Parameters

original

T
An existing object that you want to make a copy of.

position

The position for the new object or objects.

rotation

The rotation for the new object or objects.

Returns

Type

Description

AsyncInstantiateOperation<T>An asynchronous operation that contains the resulting objects.

InstantiateAsync<T>(T, Transform, Vector3, Quaternion)

Clones the object of type T asynchronously, sets the parent, position, and rotation of the clone, and returns an
AsyncInstantiateOperation
.
public static AsyncInstantiateOperation<T> InstantiateAsync<T>(T original, Transform parent, Vector3 position, Quaternion rotation) where T : Object

Parameters

original

T
An existing object that you want to make a copy of.

parent

The Transform to set as the parent of the new object.

position

The position for the new object or objects.

rotation

The rotation for the new object or objects.

Returns

Type

Description

AsyncInstantiateOperation<T>An asynchronous operation that contains the resulting objects.

InstantiateAsync<T>(T, int)

Clones the object of type T asynchronously, creates a specified number of copies, and returns an
AsyncInstantiateOperation
.
public static AsyncInstantiateOperation<T> InstantiateAsync<T>(T original, int count) where T : Object

Parameters

original

T
An existing object that you want to make a copy of.

count

The number of new copies to create.

Returns

Type

Description

AsyncInstantiateOperation<T>An asynchronous operation that contains the resulting objects.

InstantiateAsync<T>(T, int, Transform)

Clones the object of type T asynchronously, creates a specified number of copies, sets
parent
as the parent of the clones, and returns an
AsyncInstantiateOperation
.
public static AsyncInstantiateOperation<T> InstantiateAsync<T>(T original, int count, Transform parent) where T : Object

Parameters

original

T
An existing object that you want to make a copy of.

count

The number of new copies to create.

parent

The Transform to set as the parent of the new object.

Returns

Type

Description

AsyncInstantiateOperation<T>An asynchronous operation that contains the resulting objects.

InstantiateAsync<T>(T, int, Vector3, Quaternion)

Clones the object of type T asynchronously, creates a specified number of copies, sets the position and rotation of the clones, and returns an
AsyncInstantiateOperation
.
public static AsyncInstantiateOperation<T> InstantiateAsync<T>(T original, int count, Vector3 position, Quaternion rotation) where T : Object

Parameters

original

T
An existing object that you want to make a copy of.

count

The number of new copies to create.

position

The position for the new object or objects.

rotation

The rotation for the new object or objects.

Returns

Type

Description

AsyncInstantiateOperation<T>An asynchronous operation that contains the resulting objects.

InstantiateAsync<T>(T, int, ReadOnlySpan<Vector3>, ReadOnlySpan<Quaternion>)

Clones the object of type T asynchronously, creates a specified number of copies, sets the per-copy positions and rotations of the clones, and returns an
AsyncInstantiateOperation
.
public static AsyncInstantiateOperation<T> InstantiateAsync<T>(T original, int count, ReadOnlySpan<Vector3> positions, ReadOnlySpan<Quaternion> rotations) where T : Object

Parameters

original

T
An existing object that you want to make a copy of.

count

The number of new copies to create.

The read only span of positions for the new object or objects. The length of the span can be less than
count
, in which case Unity uses positions[i % positions.Length].

The read only span of rotations for the new object or objects. The length of the span can be less than
count
, in which case Unity uses rotations[i % rotations.Length].

Returns

Type

Description

AsyncInstantiateOperation<T>An asynchronous operation that contains the resulting objects.

InstantiateAsync<T>(T, int, Transform, Vector3, Quaternion)

Clones the object of type T asynchronously, creates a specified number of copies, sets the parent, position, and rotation of the clones, and returns an
AsyncInstantiateOperation
.
public static AsyncInstantiateOperation<T> InstantiateAsync<T>(T original, int count, Transform parent, Vector3 position, Quaternion rotation) where T : Object

Parameters

original

T
An existing object that you want to make a copy of.

count

The number of new copies to create.

parent

The Transform to set as the parent of the new object.

position

The position for the new object or objects.

rotation

The rotation for the new object or objects.

Returns

Type

Description

AsyncInstantiateOperation<T>An asynchronous operation that contains the resulting objects.

InstantiateAsync<T>(T, int, Transform, Vector3, Quaternion, CancellationToken)

Clones the object of type T asynchronously, creates a specified number of copies, sets the parent, position, and rotation of the clones, and returns an
AsyncInstantiateOperation
that you can cancel with
cancellationToken
.
public static AsyncInstantiateOperation<T> InstantiateAsync<T>(T original, int count, Transform parent, Vector3 position, Quaternion rotation, CancellationToken cancellationToken) where T : Object

Parameters

original

T
An existing object that you want to make a copy of.

count

The number of new copies to create.

parent

The Transform to set as the parent of the new object.

position

The position for the new object or objects.

rotation

The rotation for the new object or objects.

cancellationToken

A token that you can use to cancel the asynchronous operation before it completes.

Returns

Type

Description

AsyncInstantiateOperation<T>An asynchronous operation that contains the resulting objects.

InstantiateAsync<T>(T, int, Transform, ReadOnlySpan<Vector3>, ReadOnlySpan<Quaternion>)

Clones the object of type T asynchronously, creates a specified number of copies, sets the parent and the per-copy positions and rotations of the clones, and returns an
AsyncInstantiateOperation
.
public static AsyncInstantiateOperation<T> InstantiateAsync<T>(T original, int count, Transform parent, ReadOnlySpan<Vector3> positions, ReadOnlySpan<Quaternion> rotations) where T : Object

Parameters

original

T
An existing object that you want to make a copy of.

count

The number of new copies to create.

parent

The Transform to set as the parent of the new object.

The read only span of positions for the new object or objects. The length of the span can be less than
count
, in which case Unity uses positions[i % positions.Length].

The read only span of rotations for the new object or objects. The length of the span can be less than
count
, in which case Unity uses rotations[i % rotations.Length].

Returns

Type

Description

AsyncInstantiateOperation<T>An asynchronous operation that contains the resulting objects.

InstantiateAsync<T>(T, int, Transform, ReadOnlySpan<Vector3>, ReadOnlySpan<Quaternion>, CancellationToken)

Clones the object of type T asynchronously, creates a specified number of copies, sets the parent and the per-copy positions and rotations of the clones, and returns an
AsyncInstantiateOperation
that you can cancel with
cancellationToken
.
public static AsyncInstantiateOperation<T> InstantiateAsync<T>(T original, int count, Transform parent, ReadOnlySpan<Vector3> positions, ReadOnlySpan<Quaternion> rotations, CancellationToken cancellationToken) where T : Object

Parameters

original

T
An existing object that you want to make a copy of.

count

The number of new copies to create.

parent

The Transform to set as the parent of the new object.

The read only span of positions for the new object or objects. The length of the span can be less than
count
, in which case Unity uses positions[i % positions.Length].

The read only span of rotations for the new object or objects. The length of the span can be less than
count
, in which case Unity uses rotations[i % rotations.Length].

cancellationToken

A token that you can use to cancel the asynchronous operation before it completes.

Returns

Type

Description

AsyncInstantiateOperation<T>An asynchronous operation that contains the resulting objects.

InstantiateAsync<T>(T, InstantiateParameters, CancellationToken)

Clones the object of type T asynchronously, applies the settings in
parameters
, and returns an
AsyncInstantiateOperation
.
public static AsyncInstantiateOperation<T> InstantiateAsync<T>(T original, InstantiateParameters parameters, CancellationToken cancellationToken = default) where T : Object

Parameters

original

T
An existing object that you want to make a copy of.

An InstantiateParameters struct that specifies options for the new object, such as its parent, the scene to add it to, and whether to use world space.

cancellationToken

A token that you can use to cancel the asynchronous operation before it completes.

Returns

Type

Description

AsyncInstantiateOperation<T>An asynchronous operation that contains the resulting objects.

InstantiateAsync<T>(T, int, InstantiateParameters, CancellationToken)

Clones the object of type T asynchronously, creates a specified number of copies, applies the settings in
parameters
, and returns an
AsyncInstantiateOperation
.
public static AsyncInstantiateOperation<T> InstantiateAsync<T>(T original, int count, InstantiateParameters parameters, CancellationToken cancellationToken = default) where T : Object

Parameters

original

T
An existing object that you want to make a copy of.

count

The number of new copies to create.

An InstantiateParameters struct that specifies options for the new object, such as its parent, the scene to add it to, and whether to use world space.

cancellationToken

A token that you can use to cancel the asynchronous operation before it completes.

Returns

Type

Description

AsyncInstantiateOperation<T>An asynchronous operation that contains the resulting objects.

InstantiateAsync<T>(T, Vector3, Quaternion, InstantiateParameters, CancellationToken)

Clones the object of type T asynchronously, sets the position and rotation of the clone, applies the settings in
parameters
, and returns an
AsyncInstantiateOperation
.
public static AsyncInstantiateOperation<T> InstantiateAsync<T>(T original, Vector3 position, Quaternion rotation, InstantiateParameters parameters, CancellationToken cancellationToken = default) where T : Object

Parameters

original

T
An existing object that you want to make a copy of.

position

The position for the new object or objects.

rotation

The rotation for the new object or objects.

An InstantiateParameters struct that specifies options for the new object, such as its parent, the scene to add it to, and whether to use world space.

cancellationToken

A token that you can use to cancel the asynchronous operation before it completes.

Returns

Type

Description

AsyncInstantiateOperation<T>An asynchronous operation that contains the resulting objects.

InstantiateAsync<T>(T, int, Vector3, Quaternion, InstantiateParameters, CancellationToken)

Clones the object of type T asynchronously, creates a specified number of copies, sets the position and rotation of the clones, applies the settings in
parameters
, and returns an
AsyncInstantiateOperation
.
public static AsyncInstantiateOperation<T> InstantiateAsync<T>(T original, int count, Vector3 position, Quaternion rotation, InstantiateParameters parameters, CancellationToken cancellationToken = default) where T : Object

Parameters

original

T
An existing object that you want to make a copy of.

count

The number of new copies to create.

position

The position for the new object or objects.

rotation

The rotation for the new object or objects.

An InstantiateParameters struct that specifies options for the new object, such as its parent, the scene to add it to, and whether to use world space.

cancellationToken

A token that you can use to cancel the asynchronous operation before it completes.

Returns

Type

Description

AsyncInstantiateOperation<T>An asynchronous operation that contains the resulting objects.

InstantiateAsync<T>(T, int, ReadOnlySpan<Vector3>, ReadOnlySpan<Quaternion>, InstantiateParameters, CancellationToken)

Clones the object of type T asynchronously, creates a specified number of copies, sets the per-copy positions and rotations of the clones, applies the settings in
parameters
, and returns an
AsyncInstantiateOperation
.
public static AsyncInstantiateOperation<T> InstantiateAsync<T>(T original, int count, ReadOnlySpan<Vector3> positions, ReadOnlySpan<Quaternion> rotations, InstantiateParameters parameters, CancellationToken cancellationToken = default) where T : Object

Parameters

original

T
An existing object that you want to make a copy of.

count

The number of new copies to create.

The read only span of positions for the new object or objects. The length of the span can be less than
count
, in which case Unity uses positions[i % positions.Length].

The read only span of rotations for the new object or objects. The length of the span can be less than
count
, in which case Unity uses rotations[i % rotations.Length].

An InstantiateParameters struct that specifies options for the new object, such as its parent, the scene to add it to, and whether to use world space.

cancellationToken

A token that you can use to cancel the asynchronous operation before it completes.

Returns

Type

Description

AsyncInstantiateOperation<T>An asynchronous operation that contains the resulting objects.