unity-unitask-design

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

Updated Jun 21, 2026
One-click install
npx skills add https://github.com/du-qwq/Shader-Writing-Architecture-and-Specifications --skill unity-unitask-design-du-qwq
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: unity-unitask-design
Source: https://github.com/du-qwq/Shader-Writing-Architecture-and-Specifications/tree/main/.agents/skills/unity-skills/skills/unitask-design
Command: npx skills add https://github.com/du-qwq/Shader-Writing-Architecture-and-Specifications --skill unity-unitask-design-du-qwq

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, 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 reviewing a PR that adds async UniTask methods, load this Skill to catch double-await bugs, missing CancellationToken forwarding, undisposed AsyncReactiveProperty instances, and SwitchToThreadPool calls that crash on WebGL. ## Quick Start Ask the AI to review your async UniTask code or help you write a new UniTask-based method with proper cancellation and timing.

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 whose backing source is recycled after the first await, so awaiting the same variable twice throws InvalidOperationException. Call .Preserve() once to get a memoized copy that can be awaited multiple times, 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 through your async call chain. Plain C# classes must own and dispose their own CancellationTokenSource instead.

Does UniTask SwitchToThreadPool work on WebGL builds?

No. UniTask.SwitchToThreadPool and UniTask.RunOnThreadPool throw NotSupportedException on WebGL because the platform is single-threaded. Guard those calls with #if UNITY_WEBGL && !UNITY_EDITOR and fall back to synchronous or Yield-based cooperative 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 my UniTask async method swallow exceptions silently?

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

How do I convert Unity AsyncOperation or UnityWebRequest to UniTask?

Call .ToUniTask() on the operation, passing an IProgress<float> and CancellationToken as needed. For UnityWebRequest, wrap the await in try/catch for UnityWebRequestException, since plain await does not throw on HTTP errors.