unity-unitask-design

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

Updated Aug 31, 2026
One-click install
npx skills add https://github.com/pikachu0310/codex-agent-ops-public --skill unity-unitask-design-pikachu0310
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: unity-unitask-design
Source: https://github.com/pikachu0310/codex-agent-ops-public/tree/main/.agents/skills/unity-skills/skills/unitask-design
Command: npx skills add https://github.com/pikachu0310/codex-agent-ops-public --skill unity-unitask-design-pikachu0310

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 choices, 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 does not rely on stale or hallucinated API knowledge. ## Core Features & Use Cases - Source-anchored rule set: Ten critical rules covering UniTask struct semantics, Preserve(), Forget(), PlayerLoopTiming, DelayType, cancellation, WhenAll/WhenAny, and WebGL constraints, each citing exact source locations. - Routed sub-documents: Seven reference files (BASICS, PLAYERLOOP, CANCELLATION, COMPOSITION, CONVERSION, ASYNCENUMERABLE, TRIGGERS) loaded on demand for deep dives into specific API areas. - Pitfall catalog: 30 concrete wrong-vs-right patterns (double await, missing Forget, undisposed AsyncReactiveProperty, DOTween bridge misuse) for code review and onboarding. - Use Case: When reviewing a pull request that adds async UniTask methods with UnityWebRequest.SendWebRequest().ToUniTask(), load this Skill to verify cancellation tokens are forwarded, progress callbacks use Progress.Create, and UnityWebRequestException is caught. ## Quick Start Ask the AI to review your UniTask async method or design a new async workflow using the unitask-design rules before writing any code.

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 the double-await error 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 MonoBehaviour is destroyed?

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

Does UniTask.SwitchToThreadPool work on WebGL builds?

No. UniTask.SwitchToThreadPool, UniTask.Run, and RunOnThreadPool compile on all platforms but throw NotSupportedException at runtime on WebGL because it is single-threaded. Guard those calls with #if !UNITY_WEBGL || UNITY_EDITOR and fall back to cooperative yielding.

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.

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, and enable the UniTask Analyzer to catch this pattern.