Awaitable
Custom Unity type that can be awaited and used as an async return type in the C# asynchronous programming model.
Read time 1 minuteLast updated 4 days ago
Definition
- Type: Class
- Namespace: UnityEngine
- Assembly: UnityEngine.CoreModule
- Implements: IEnumerator
public class Awaitable : IEnumerator
Remarks
AwaitableTaskAwaitableawaitFor more information, refer to Asynchronous programming with the Awaitable class in the Manual.
Examples
private async Awaitable DoSomethingAsync(){ await LoadSceneAsync("SomeScene"); await SomeApiReturningATask(); await Awaitable.NextFrameAsync(); // <...>}
Properties
Property | Description |
|---|---|
| IsCompleted | Indicates if the awaitable has run to completion. |
Methods
Method | Description |
|---|---|
| Cancel | Cancels the awaitable. If the awaitable is being awaited, the awaiter receives a System.OperationCanceledException. |
| LogExceptionsAndForget | Configures the async method to log exceptions without an explicit result check. |
Static Methods
Method | Description |
|---|---|
| BackgroundThreadAsync | Resumes execution on a ThreadPool background thread. Completes immediately when called from a background thread. |
| EndOfFrameAsync | Resumes execution after all Unity subsystems have run for the current frame. |
| FixedUpdateAsync | Resumes execution on the next fixed update frame. |
| FromAsyncOperation | Creates an Awaitable from an existing AsyncOperation object. |
| MainThreadAsync | Resumes execution on the Unity main thread. Completes immediately when called from the main thread. |
| NextFrameAsync | Resumes execution on the next frame. |
| WaitForSecondsAsync | Resumes execution after the specified number of seconds. |