Version: Unity 6.6 Beta (6000.6)
LanguageEnglish
  • C#

Object.InstantiateAsync

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual

Declaration

public static AsyncInstantiateOperation<T> InstantiateAsync(T original);

Parameters

Parameter Description
original An existing object that you want to make a copy of.

Returns

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

Description

Captures a snapshot of the original object that's related to another GameObject and obtains an AsyncInstantiateOperation instance of the resulting objects.

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.


Declaration

public static AsyncInstantiateOperation<T> InstantiateAsync(T original, Transform parent);

Parameters

Parameter Description
original An existing object that you want to make a copy of.
parent The Transform to set as the parent of the new object.

Returns

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

Description

Clones the object of type T asynchronously, sets parent as the parent of the clone, and returns an AsyncInstantiateOperation.


Declaration

public static AsyncInstantiateOperation<T> InstantiateAsync(T original, Transform parent, Vector3 position, Quaternion rotation);

Parameters

Parameter Description
original 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

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

Description

Clones the object of type T asynchronously, sets the parent, position, and rotation of the clone, and returns an AsyncInstantiateOperation.


Declaration

public static AsyncInstantiateOperation<T> InstantiateAsync(T original, Vector3 position, Quaternion rotation);

Parameters

Parameter Description
original 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

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

Description

Clones the object of type T asynchronously, sets the position and rotation of the clone, and returns an AsyncInstantiateOperation.


Declaration

public static AsyncInstantiateOperation<T> InstantiateAsync(T original, Vector3 position, Quaternion rotation, InstantiateParameters parameters, CancellationToken cancellationToken);

Parameters

Parameter Description
original 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.
parameters 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

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

Description

Clones the object of type T asynchronously, sets the position and rotation of the clone, applies the settings in parameters, and returns an AsyncInstantiateOperation.


Declaration

public static AsyncInstantiateOperation<T> InstantiateAsync(T original, InstantiateParameters parameters, CancellationToken cancellationToken);

Parameters

Parameter Description
original An existing object that you want to make a copy of.
parameters 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

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

Description

Clones the object of type T asynchronously, applies the settings in parameters, and returns an AsyncInstantiateOperation.


Declaration

public static AsyncInstantiateOperation<T> InstantiateAsync(T original, int count);

Parameters

Parameter Description
original An existing object that you want to make a copy of.
count The number of new copies to create.

Returns

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

Description

Clones the object of type T asynchronously, creates a specified number of copies, and returns an AsyncInstantiateOperation.


Declaration

public static AsyncInstantiateOperation<T> InstantiateAsync(T original, int count, InstantiateParameters parameters, CancellationToken cancellationToken);

Parameters

Parameter Description
original An existing object that you want to make a copy of.
count The number of new copies to create.
parameters 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

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

Description

Clones the object of type T asynchronously, creates a specified number of copies, applies the settings in parameters, and returns an AsyncInstantiateOperation.


Declaration

public static AsyncInstantiateOperation<T> InstantiateAsync(T original, int count, Transform parent);

Parameters

Parameter Description
original 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

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

Description

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.


Declaration

public static AsyncInstantiateOperation<T> InstantiateAsync(T original, int count, Transform parent, Vector3 position, Quaternion rotation, CancellationToken cancellationToken);

Parameters

Parameter Description
original 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

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

Description

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.


Declaration

public static AsyncInstantiateOperation<T> InstantiateAsync(T original, int count, Transform parent, ReadOnlySpan<Vector3> positions, ReadOnlySpan<Quaternion> rotations, CancellationToken cancellationToken);

Parameters

Parameter Description
original 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.
positions 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].
rotations 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

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

Description

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.


Declaration

public static AsyncInstantiateOperation<T> InstantiateAsync(T original, int count, Vector3 position, Quaternion rotation);

Parameters

Parameter Description
original 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

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

Description

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.


Declaration

public static AsyncInstantiateOperation<T> InstantiateAsync(T original, int count, Vector3 position, Quaternion rotation, InstantiateParameters parameters, CancellationToken cancellationToken);

Parameters

Parameter Description
original 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.
parameters 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

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

Description

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.


Declaration

public static AsyncInstantiateOperation<T> InstantiateAsync(T original, int count, ReadOnlySpan<Vector3> positions, ReadOnlySpan<Quaternion> rotations);

Parameters

Parameter Description
original An existing object that you want to make a copy of.
count The number of new copies to create.
positions 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].
rotations 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

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

Description

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.


Declaration

public static AsyncInstantiateOperation<T> InstantiateAsync(T original, int count, ReadOnlySpan<Vector3> positions, ReadOnlySpan<Quaternion> rotations, InstantiateParameters parameters, CancellationToken cancellationToken);

Parameters

Parameter Description
original An existing object that you want to make a copy of.
count The number of new copies to create.
positions 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].
rotations 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].
parameters 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

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

Description

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.


Declaration

public static AsyncInstantiateOperation<T> InstantiateAsync(T original, int count, Transform parent, Vector3 position, Quaternion rotation);

Parameters

Parameter Description
original 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

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

Description

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.


Declaration

public static AsyncInstantiateOperation<T> InstantiateAsync(T original, int count, Transform parent, ReadOnlySpan<Vector3> positions, ReadOnlySpan<Quaternion> rotations);

Parameters

Parameter Description
original 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.
positions 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].
rotations 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

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

Description

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.