unity-unitask-design

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

2|Updated May 18, 2026
One-click install
npx skills add https://github.com/pcone-mm/NewFPG --skill unity-unitask-design-pcone-mm
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: unity-unitask-design
Source: https://github.com/pcone-mm/NewFPG/tree/main/.agents/skills/unity-skills/skills/unitask-design
Command: npx skills add https://github.com/pcone-mm/NewFPG --skill unity-unitask-design-pcone-mm

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, Preserve(), Forget(), PlayerLoopTiming, DelayType, cancellation, WhenAll/WhenAny, and WebGL constraints, each citing exact source locations. - Eight deep-dive sub-docs: BASICS, PLAYERLOOP, CANCELLATION, COMPOSITION, CONVERSION, ASYNCENUMERABLE, TRIGGERS, and a 30-item PITFALLS catalog with wrong-vs-right code pairs. - Use Case: When asked to write an async asset-loading flow, the Skill routes to CONVERSION.md for AssetBundle.LoadFromFileAsync().ToUniTask() with progress and cancellation, then to PITFALLS.md to avoid double-await and unscoped subscription leaks. ## Quick Start Ask the AI to review or write an async UniTask method, such as loading an AssetBundle with progress reporting and cancellation on GameObject destroy.

Frequently Asked Questions about unity-unitask-design

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

FAQPage Schema
How do I await a UniTask multiple times without exceptions?

Call .Preserve() once on the UniTask to memoize its backing source, then await the preserved value repeatedly. Awaiting a raw UniTask twice throws InvalidOperationException because UniTask is a struct whose pooled IUniTaskSource is recycled after the first await.

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

Use this.GetCancellationTokenOnDestroy() on a MonoBehaviour, GameObject, or Component, and pass the token into every cancellation-aware call like UniTask.Delay. Plain C# classes lack this extension and must own and dispose their own CancellationTokenSource.

Does UniTask.SwitchToThreadPool work on WebGL builds?

No. UniTask.SwitchToThreadPool, UniTask.Run, and RunOnThreadPool 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.

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 continuation on a subsequent frame. Use NextFrame to split work across frames and Yield(timing) to target a specific phase.

Why does awaiting the same UniTask variable twice throw an error?

UniTask is a readonly struct wrapping an IUniTaskSource and a version token. After the first await, the source returns to the pool and the token becomes stale, so the second await throws InvalidOperationException. Use .Preserve() or invoke the async method again.

When should I use AsyncOperation.ToUniTask instead of awaiting directly?

Use .ToUniTask() whenever you need progress reporting via IProgress<float>, cancellation via CancellationToken, or typed results like AssetBundle from AssetBundleCreateRequest. A bare await compiles but wires up none of these and can silently leak progress callbacks.