unity-unitask-design

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

Updated May 20, 2026
One-click install
npx skills add https://github.com/yuse168/Roomies --skill unity-unitask-design-yuse168
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: unity-unitask-design
Source: https://github.com/yuse168/Roomies/tree/main/.agents/skills/unity-skills/skills/unitask-design
Command: npx skills add https://github.com/yuse168/Roomies --skill unity-unitask-design-yuse168

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, WebGL thread pool crashes, and subscription leaks cause production bugs that are hard to diagnose. 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, AsyncOperation conversion, and WebGL constraints, each citing exact source locations. - Eight deep-dive sub-docs: BASICS, PLAYERLOOP, CANCELLATION, COMPOSITION, CONVERSION, ASYNCENUMERABLE, TRIGGERS, and PITFALLS (30 concrete failure patterns with wrong/right code pairs). - Use Case: When reviewing a PR that adds async UniTask methods, load this Skill to catch double-await bugs, missing CancellationToken forwarding, undisposed AsyncReactiveProperty instances, and UniTask.RunOnThreadPool calls that will crash on WebGL builds. ## Quick Start Review my Unity async code that uses UniTask and check it against the UniTask design rules and pitfalls.

Frequently Asked Questions about unity-unitask-design

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

FAQPage Schema
How do I avoid double-await errors with UniTask in Unity?▼

UniTask is a struct wrapping a pooled source, so awaiting the same UniTask variable twice throws InvalidOperationException. Call .Preserve() once to get a memoized copy that supports multiple awaits, or invoke the async method again for a fresh UniTask.

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

Use this.GetCancellationTokenOnDestroy(), available on MonoBehaviour, GameObject, and Component, and pass the token into every async call. Plain C# classes must own a CancellationTokenSource and cancel plus dispose it in their Dispose method.

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 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. UniTask.NextFrame guarantees the continuation runs on a subsequent frame, making it the right choice for splitting work across frames.

Why does my UniTask async method swallow exceptions silently?▼

A returned UniTask that is neither awaited nor .Forget()ed drops its result, and exceptions surface only through UniTaskScheduler.UnobservedTaskException. Always await the UniTask or call .Forget() with an exception handler for fire-and-forget work.

When should I use AsyncReactiveProperty versus Channel in UniTask?▼

AsyncReactiveProperty suits a single mutable value whose changes subscribers observe, and it must be disposed to release subscribers. Channel<T> fits producer-consumer scenarios with independent rates, using Writer.TryWrite and Reader.ReadAllAsync for buffered consumption.