Navigate:
All ReposUniTask
~$UNITAS0.1%

UniTask: Allocation-free async/await for Unity

Zero-allocation async/await using structs and custom method builders.

LIVE RANKINGS • 06:50 AM • STEADY
OVERALL
#149
26
DEVELOPER TOOLS
#29
9
30 DAY RANKING TREND
ovr#149
·Devel#29
STARS
10.4K
FORKS
965
DOWNLOADS
7D STARS
+11
7D FORKS
+1
See Repo:
Share:

Learn more about UniTask

UniTask is a high-performance asynchronous programming library for Unity that provides allocation-free async/await functionality through value-type task structures. It replaces the standard .NET Task-based model with custom struct-based implementations and specialized async method builders that avoid heap allocations during asynchronous operations. The library integrates directly with Unity's player loop system to schedule continuation callbacks without requiring additional thread synchronization or context switching overhead. It provides awaitable wrappers for Unity-specific operations such as frame delays, coroutine integration, and lifecycle events, enabling async patterns within Unity's single-threaded execution model. The zero-allocation design significantly reduces garbage collection pressure in performance-critical game scenarios where frequent asynchronous operations would otherwise cause memory churn.

UniTask

1

Struct-based implementation

UniTask uses value types (structs) instead of reference types for task objects, combined with custom AsyncMethodBuilder to eliminate heap allocations during async/await operations. This reduces garbage collection pressure compared to standard Task-based approaches.

2

PlayerLoop integration

Operations execute within Unity's PlayerLoop system rather than on background threads, ensuring compatibility with single-threaded platforms like WebGL and wasm. This design allows frame-based timing and synchronization with Unity's lifecycle events.

3

Awaitable Unity APIs

The library wraps Unity's AsyncOperations, coroutines, and UI events as awaitable objects, allowing them to be used directly with async/await syntax. It also provides PlayerLoop-based alternatives to coroutine operations like WaitForSeconds and yield return null.


public async UniTaskVoid LoadManyAsync()
{
    // parallel load.
    var (a, b, c) = await UniTask.WhenAll(
        LoadAsSprite("foo"),
        LoadAsSprite("bar"),
        LoadAsSprite("baz"));
}

async UniTask<Sprite> LoadAsSprite(string path)
{
    var resource = await Resources.LoadAsync<Sprite>(path);
    return (resource as Sprite);
}

v2.5.10

Patches compilation errors affecting Unity 2020.1 and earlier versions.

  • Upgrade if running Unity 2020.1 or older to restore builds broken by 2.5.9.
  • Release notes do not specify which APIs or code paths triggered the compilation failures.
v2.5.9

Adds AsyncInstantiateOperation helpers for Unity 2022.3.20+ and 2023.3+; drops Unity 2021 LTS from CI (no runtime impact stated).

  • Use AsyncInstantiateOperation.WithCancellation or ToUniTask if running Unity 2022.3.20, 2023.3, or newer.
  • Unity 2021 LTS removed from build matrix; release notes do not specify if runtime support is dropped.
v2.5.8

Adds Unity 2023.1+ compatibility note to prevent compilation errors and introduces UniTask.WhenEach for iterating tasks as they complete.

  • Check documentation for Unity 2023.1+ setup steps to avoid compilation errors (specific changes not detailed in notes).
  • Use new UniTask.WhenEach method to process multiple tasks as each completes, plus generic UnityAction support added.


[ EXPLORE MORE ]

Related Repositories

Discover similar tools and frameworks used by developers