unity-unitask-design

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

Updated Aug 18, 2026
One-click install
npx skills add https://github.com/ethanJPope/Our-Main-Hackathon-Game --skill unity-unitask-design-ethanjpope
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: unity-unitask-design
Source: https://github.com/ethanJPope/Our-Main-Hackathon-Game/tree/main/.agents/skills/unity-skills/skills/unitask-design
Command: npx skills add https://github.com/ethanJPope/Our-Main-Hackathon-Game --skill unity-unitask-design-ethanjpope

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing async code in Unity with UniTask is error-prone: struct-based 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 UniTask struct semantics, Preserve(), Forget(), PlayerLoopTiming, DelayType, cancellation tokens, WhenAll/WhenAny, and WebGL constraints, each citing exact source locations. - Topical sub-documents: Deep references for basics, PlayerLoop timing, cancellation, composition, conversion/interop, AsyncEnumerable/reactive streams, lifecycle triggers, and 30 concrete pitfalls. - Use Case: Before writing an async UniTask method that loads an AssetBundle with progress and cancellation, load this Skill to get the correct ToUniTask(progress, cancellationToken) signature, the GetCancellationTokenOnDestroy() pattern, and the checklist for avoiding double-await and subscription leaks. ## Quick Start Ask the AI to review or write UniTask async code for Unity, such as a cancellable asset-loading method with progress reporting, and have it apply the UniTask design rules and pitfall checklist.

Frequently Asked Questions about unity-unitask-design

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

FAQPage Schema
How do I write async code in Unity with UniTask?

Return UniTask, UniTask<T>, or UniTaskVoid from async methods instead of Task, and always await the result or call .Forget(). Accept a CancellationToken as the last parameter and forward it to primitives like UniTask.Delay so cancellation propagates correctly.

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 UniTask that can be awaited multiple times.

How do I cancel UniTask operations when a GameObject is destroyed?

Call this.GetCancellationTokenOnDestroy() on a MonoBehaviour, GameObject, or Component to get a token that cancels on OnDestroy. Plain C# classes must own and dispose their own CancellationTokenSource instead.

Does UniTask.RunOnThreadPool work on WebGL builds?

No. UniTask.Run, RunOnThreadPool, and SwitchToThreadPool throw NotSupportedException on WebGL because the platform is single-threaded. Guard those calls with #if UNITY_WEBGL && !UNITY_EDITOR and run the work synchronously as a fallback.

What is the difference between UniTask.Yield and UniTask.NextFrame?

UniTask.Yield may resume on the same frame if awaited from an earlier PlayerLoop phase than the target timing, while NextFrame guarantees the continuation runs on a subsequent frame. Use NextFrame to split work across frames and Yield(timing) to target a specific phase.

How do I convert AsyncOperation or UnityWebRequest to UniTask?

Call .ToUniTask() on the operation, optionally passing an IProgress<float> and CancellationToken. For UnityWebRequest, wrap the await in try/catch for UnityWebRequestException to inspect Result, ResponseCode, and Error on failure.