unity-unitask-design

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

Updated Jan 29, 2026
One-click install
npx skills add https://github.com/Dylan8865/FinalYearProject --skill unity-unitask-design-dylan8865
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: unity-unitask-design
Source: https://github.com/Dylan8865/FinalYearProject/tree/main/GameDev/Tester/.agents/skills/unity-skills/skills/unitask-design
Command: npx skills add https://github.com/Dylan8865/FinalYearProject --skill unity-unitask-design-dylan8865

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing async code in Unity with UniTask introduces subtle failure modes—double-awaiting struct-based tasks, forgotten cancellation tokens, WebGL thread pool crashes, and subscription leaks—that standard Task-based intuition does not cover. This Skill grounds every rule in the actual UniTask 2.5.10 source code so AI-generated or reviewed async code avoids these pitfalls. ## Core Features & Use Cases - Source-Anchored Rules: Ten critical rules covering struct semantics, PlayerLoopTiming, cancellation, composition, and conversion, each citing exact file and line references in the UniTask source. - Eight Sub-Reference Documents: Deep dives into basics, PlayerLoop timing, cancellation, composition (WhenAll/WhenAny/WhenEach), interop conversion, async enumerables, lifecycle triggers, and 30 concrete pitfalls. - Use Case: When reviewing a pull request that adds async UniTask methods to a Unity MonoBehaviour, load this Skill to verify cancellation tokens are forwarded, .Forget() is called on fire-and-forget tasks, and WebGL-unsafe thread pool calls are guarded. ## Quick Start Ask the AI to review your async UniTask code or help you write a new async UniTask method with proper cancellation handling.

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 obtain 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 into every async UniTask call. Plain C# classes must own and dispose their own CancellationTokenSource instead.

Does UniTask.SwitchToThreadPool work on WebGL builds?▼

No. SwitchToThreadPool and UniTask.RunOnThreadPool throw NotSupportedException on WebGL because the platform is single-threaded. Guard such 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?▼

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 task or call .Forget() with an exception handler for fire-and-forget work.

How do I convert Unity AsyncOperation or coroutines to UniTask?▼

Call .ToUniTask() on AsyncOperation, UnityWebRequestAsyncOperation, or a started Coroutine to get typed results, progress callbacks, and cancellation support. Plain await on an AsyncOperation compiles but skips progress and cancellation wiring.