gitmyhub

UniTask

C# ★ 11k updated 19d ago

Provides an efficient allocation free async/await integration for Unity.

A C# library for Unity that replaces coroutines with async/await code that produces zero heap allocations, keeping games running smoothly while making asynchronous logic easier to read and maintain.

C#Unitysetup: moderatecomplexity 3/5

UniTask is a C# library for Unity that gives you a cleaner way to write asynchronous code in your game or application. Instead of relying on coroutines or Unity's older async patterns, you can use async/await syntax, which lets you express step-by-step operations in a readable, sequential style without callback nesting.

The core design goal is to avoid wasting memory. Standard C# tasks allocate memory on the heap each time they run, which can cause slowdowns in games that need consistent frame rates. UniTask uses a struct-based design so that awaiting an operation typically produces no heap allocation at all. It integrates directly with Unity's player loop rather than spawning threads, which means it works correctly on platforms like WebGL that do not support threads.

Practically speaking, UniTask lets you await almost anything Unity produces: loading assets, web requests, scene transitions, physics updates, and even the old coroutine-style IEnumerator methods. There are also helper methods to replace common coroutine patterns, such as waiting for a fixed number of frames, waiting for a time delay, or waiting until a condition becomes true.

For more advanced work, UniTask includes an Async LINQ feature that lets you process sequences of values that arrive over time, similar to how LINQ works on regular collections. There is also a TaskTracker window built into the Unity editor that shows you which tasks are currently running and helps spot ones that were never completed, which is a common source of memory leaks in async Unity code.

The library targets Unity 2018.3 and later. It is compatible with the standard .NET Task and ValueTask types, so existing code that already uses those patterns can gradually adopt UniTask without a full rewrite. The full README is longer than what was shown.

Where it fits