unity-unitask-design

Provides source-anchored design rules for writing and reviewing UniTask async code in Unity.

Updated Oct 13, 2025
One-click install
npx skills add https://github.com/Darth-Carrotpie/ProxyCore --skill unity-unitask-design-darth-carrotpie
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: unity-unitask-design
Source: https://github.com/Darth-Carrotpie/ProxyCore/tree/main/.agents/skills/unity-skills/skills/unitask-design
Command: npx skills add https://github.com/Darth-Carrotpie/ProxyCore --skill unity-unitask-design-darth-carrotpie

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing async code in Unity with UniTask is error-prone: struct single-await semantics, forgotten cancellation tokens, wrong PlayerLoopTiming, and WebGL thread-pool crashes cause subtle production bugs. This Skill grounds every rule in the actual UniTask 2.5.10 source (file and line citations) so AI-generated or reviewed async code avoids hallucinated APIs and known pitfalls. ## Core Features & Use Cases - Source-anchored rule set: Ten critical rules covering struct semantics, PlayerLoop timing, cancellation, composition, and conversion, each citing concrete UniTask source locations. - Eight deep-dive sub-docs: BASICS, PLAYERLOOP, CANCELLATION, COMPOSITION, CONVERSION, ASYNCENUMERABLE, TRIGGERS, and PITFALLS (30 concrete failure patterns) loaded on demand. - Use Case: When asked to write an async enemy AI loop, the Skill enforces passing CancellationToken through the call chain, scoping EveryValueChanged subscriptions to GetCancellationTokenOnDestroy, and guarding RunOnThreadPool for WebGL targets. ## Quick Start Ask the agent to review or write an async UniTask method, such as a cancellable asset-loading routine with progress reporting, and it will apply the UniTask design rules automatically.

Frequently Asked Questions about unity-unitask-design

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I cancel a UniTask when a MonoBehaviour is destroyed?▼

Call this.GetCancellationTokenOnDestroy() on the MonoBehaviour, GameObject, or Component and pass the token into every async UniTask method in the chain. Plain C# classes lack this extension and must own and dispose their own CancellationTokenSource.

Why does awaiting the same UniTask twice throw an exception?▼

UniTask is a struct wrapping a pooled IUniTaskSource and token; after the first await the source is recycled, so a second await throws InvalidOperationException. Call .Preserve() once to get a memoized copy that supports multiple awaits.

UniTask vs Task in Unity: which should I use?▼

UniTask avoids per-await allocations by using a struct and pooled state machine, making it suited for Unity's frame-driven loop, while Task allocates per operation. Convert between them with AsUniTask() and AsTask() when interoperating with .NET libraries.

Does UniTask.RunOnThreadPool work on WebGL builds?▼

No. UniTask.RunOnThreadPool, UniTask.Run, and SwitchToThreadPool throw NotSupportedException on WebGL because the platform is single-threaded. Guard such calls with #if UNITY_WEBGL && !UNITY_EDITOR and fall back to cooperative Yield-based work.

How do I await a UnityWebRequest with progress in UniTask?▼

Call request.SendWebRequest().ToUniTask(progress: Progress.Create<float>(...), cancellationToken: ct) and catch UnityWebRequestException for network failures. A plain await on the operation skips progress wiring, cancellation, and typed error handling.

When should I use UniTask.Delay versus UniTask.Yield?▼

Use UniTask.Yield or NextFrame to back off one frame and Delay with an explicit DelayType (DeltaTime, UnscaledDeltaTime, Realtime) for time-based waits. Delay(0) still pumps through the PlayerLoop, so it is not a same-frame yield.