UniTask: Allocation-free async/await for Unity
Zero-allocation async/await using structs and custom method builders.
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.
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.
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.
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.
using Cysharp.Threading.Tasks;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;
public class BasicUniTaskExample : MonoBehaviour
{
async UniTask<string> LoadAssetsAsync()
{
// Await Unity's AsyncObject operations
var asset = await Resources.LoadAsync<TextAsset>("config");
// Await web requests
var webRequest = UnityWebRequest.Get("https://api.example.com/data");
var response = await webRequest.SendWebRequest();
string jsonData = response.downloadHandler.text;
// Load scenes asynchronously
await SceneManager.LoadSceneAsync("GameScene");
return jsonData;
}
}See how people are using UniTask
Top in Developer Tools
Related Repositories
Discover similar tools and frameworks used by developers
FlameGraph
Converts profiling data into interactive SVG flame graphs for performance analysis.
pybind11
Header-only library creating minimal-boilerplate C++ Python bindings.
Dear ImGui
Immediate mode GUI library for 3D applications.
Keiyoushi Extensions
Extension management for the Keiyoushi multi-source content aggregation platform.
Create T3 App
Interactive CLI for scaffolding typesafe Next.js applications with the T3 Stack technology combination.
Related Reading
Guides and comparisons from the Greptile content library
How to Detect if Code Is AI-Generated
How to tell if code was written by AI: detection methods, seven common tells, the bug patterns that show up more often in agent-written PRs, and why knowing where AI code lives should change how you review it.
Best CodeRabbit Alternatives for Smarter AI Code Reviews in 2026
7 powerful CodeRabbit alternatives ranked by real dev teams. Feature comparison, pricing analysis, and honest reviews to find your perfect AI code reviewer.
27 Code Quality Tools that Catch Bugs [2026 Review]
The best code quality tools that catch bugs, security vulnerabilities, and runtime errors, sorted by language, with type, noise level, cost, and who each one is for.
Best AI Code Review Tools for GitHub
Top-rated AI code review tools for GitHub teams in 2025. Compare features, pricing, and accuracy to find the perfect fit for faster PR reviews and bulletproof code quality.