[ Web Proxy ]
URL:
Viewing: https://docs.unity3d.com/ScriptReference/Awaitable.html [Back]  [Original]

Unity - Scripting API: Awaitable
Version: Unity 6.5 (6000.5)
    • Supported
    • Legacy
    LanguageEnglish
    • C#

    Awaitable

    class in UnityEngine

    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
    Your name Your email Suggestion* Submit suggestion

    Cancel

    Description

    Custom Unity type that can be awaited and used as an async return type in the C# asynchronous programming model.

    Awaitable is usually a preferable alternative to .NET Task for asynchronous code in Unity. It's important, however, to know the differences between the two. Most notably, instances of the `Awaitable` class are pooled and therefore not safe to await multiple times in the same method.

    For more information, refer to Asynchronous programming with the Awaitable class in the Manual.

    private async Awaitable DoSomethingAsync()
    {
       await LoadSceneAsync("SomeScene");
       await SomeApiReturningATask();
       await Awaitable.NextFrameAsync();
       // <...>
    }
    

    Properties

    Property Description
    IsCompletedIndicates if the awaitable has run to completion.

    Public Methods

    Method Description
    CancelCancels the awaitable. If the awaitable is being awaited, the awaiter receives a System.OperationCanceledException.
    LogExceptionsAndForgetConfigures the async method to log exceptions without an explicit result check.

    Static Methods

    Method Description
    BackgroundThreadAsyncResumes execution on a ThreadPool background thread. Completes immediately when called from a background thread.
    EndOfFrameAsyncResumes execution after all Unity subsystems have run for the current frame.
    FixedUpdateAsyncResumes execution on the next fixed update frame.
    FromAsyncOperationCreates an Awaitable from an existing AsyncOperation object.
    MainThreadAsyncResumes execution on the Unity main thread. Completes immediately when called from the main thread.
    NextFrameAsyncResumes execution on the next frame.
    WaitForSecondsAsyncResumes execution after the specified number of seconds.

    Web Proxy Viewer  |  New URL  |  Original Page