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
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 as the parent of the clone, and returns an .
parentAsyncInstantiateOperationpublic static AsyncInstantiateOperation<T> InstantiateAsync<T>(T original, Transform parent) where T : Object
Parameters
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 .
AsyncInstantiateOperationpublic static AsyncInstantiateOperation<T> InstantiateAsync<T>(T original, Vector3 position, Quaternion rotation) where T : Object
Parameters
The position for the new object or objects.
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 .
AsyncInstantiateOperationpublic static AsyncInstantiateOperation<T> InstantiateAsync<T>(T original, Transform parent, Vector3 position, Quaternion rotation) where T : Object
Parameters
The position for the new object or objects.
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 .
AsyncInstantiateOperationpublic static AsyncInstantiateOperation<T> InstantiateAsync<T>(T original, int count) where T : Object
Parameters
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 as the parent of the clones, and returns an .
parentAsyncInstantiateOperationpublic static AsyncInstantiateOperation<T> InstantiateAsync<T>(T original, int count, Transform parent) where T : Object
Parameters
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 .
AsyncInstantiateOperationpublic static AsyncInstantiateOperation<T> InstantiateAsync<T>(T original, int count, Vector3 position, Quaternion rotation) where T : Object
Parameters
The number of new copies to create.
The position for the new object or objects.
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 .
AsyncInstantiateOperationpublic static AsyncInstantiateOperation<T> InstantiateAsync<T>(T original, int count, ReadOnlySpan<Vector3> positions, ReadOnlySpan<Quaternion> rotations) where T : Object
Parameters
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 , in which case Unity uses positions[i % positions.Length].
countThe read only span of rotations for the new object or objects. The length of the span can be less than , in which case Unity uses rotations[i % rotations.Length].
countReturns
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 .
AsyncInstantiateOperationpublic static AsyncInstantiateOperation<T> InstantiateAsync<T>(T original, int count, Transform parent, Vector3 position, Quaternion rotation) where T : Object
Parameters
The number of new copies to create.
The position for the new object or objects.
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 that you can cancel with .
AsyncInstantiateOperationcancellationTokenpublic static AsyncInstantiateOperation<T> InstantiateAsync<T>(T original, int count, Transform parent, Vector3 position, Quaternion rotation, CancellationToken cancellationToken) where T : Object
Parameters
The number of new copies to create.
The position for the new object or objects.
The rotation for the new object or objects.
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 .
AsyncInstantiateOperationpublic static AsyncInstantiateOperation<T> InstantiateAsync<T>(T original, int count, Transform parent, ReadOnlySpan<Vector3> positions, ReadOnlySpan<Quaternion> rotations) where T : Object
Parameters
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 , in which case Unity uses positions[i % positions.Length].
countThe read only span of rotations for the new object or objects. The length of the span can be less than , in which case Unity uses rotations[i % rotations.Length].
countReturns
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 that you can cancel with .
AsyncInstantiateOperationcancellationTokenpublic static AsyncInstantiateOperation<T> InstantiateAsync<T>(T original, int count, Transform parent, ReadOnlySpan<Vector3> positions, ReadOnlySpan<Quaternion> rotations, CancellationToken cancellationToken) where T : Object
Parameters
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 , in which case Unity uses positions[i % positions.Length].
countThe read only span of rotations for the new object or objects. The length of the span can be less than , in which case Unity uses rotations[i % rotations.Length].
countA 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 , and returns an .
parametersAsyncInstantiateOperationpublic static AsyncInstantiateOperation<T> InstantiateAsync<T>(T original, InstantiateParameters parameters, CancellationToken cancellationToken = default) where T : Object
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.
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 , and returns an .
parametersAsyncInstantiateOperationpublic static AsyncInstantiateOperation<T> InstantiateAsync<T>(T original, int count, InstantiateParameters parameters, CancellationToken cancellationToken = default) where T : Object
Parameters
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.
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 , and returns an .
parametersAsyncInstantiateOperationpublic static AsyncInstantiateOperation<T> InstantiateAsync<T>(T original, Vector3 position, Quaternion rotation, InstantiateParameters parameters, CancellationToken cancellationToken = default) where T : Object
Parameters
The position for the new object or objects.
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.
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 , and returns an .
parametersAsyncInstantiateOperationpublic static AsyncInstantiateOperation<T> InstantiateAsync<T>(T original, int count, Vector3 position, Quaternion rotation, InstantiateParameters parameters, CancellationToken cancellationToken = default) where T : Object
Parameters
The number of new copies to create.
The position for the new object or objects.
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.
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 , and returns an .
parametersAsyncInstantiateOperationpublic static AsyncInstantiateOperation<T> InstantiateAsync<T>(T original, int count, ReadOnlySpan<Vector3> positions, ReadOnlySpan<Quaternion> rotations, InstantiateParameters parameters, CancellationToken cancellationToken = default) where T : Object
Parameters
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 , in which case Unity uses positions[i % positions.Length].
countThe read only span of rotations for the new object or objects. The length of the span can be less than , in which case Unity uses rotations[i % rotations.Length].
countAn 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.
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. |