Skip to content

UniTask

UniTask ↗ is an open-sourced (MIT license) library providing a more efficient Task-based asynchronous programming ↗ implementation for Unity. You can find more details regarding the nature of optimizations and usage examples in the article by the author of the library ↗.

Naninovel uses a stripped and modified version of UniTask v1, which is embedded inside the engine runtime assembly; most of the asynchronous methods return UniTask objects, which you can await in the same way as default Task objects from the "System.Threading" namespace.

In case you want to use full standalone UniTask library, install UniTask v2 from the official repository: github.com/Cysharp/UniTask ↗ and specify "Naninovel.UniTask" for the Naninovel APIs when required, eg:

csharp
using Naninovel;
using UnityEngine;

public class UniTaskCommand : Command
{
    // This method uses embedded UniTask v1.
    public override async Naninovel.UniTask Execute (AsyncToken token = default)
    {
        var message = await WaitAndReturnMessage();
        Debug.Log(message);
    }

    // This method uses standalone UniTask v2.
    private async Cysharp.Threading.Tasks.UniTask<string> WaitAndReturnMessage ()
    {
        await Cysharp.Threading.Tasks.UniTask.DelayFrame(100);
        return "Hello from UniTask v2!";
    }
}