unity-unitask

UniTask library expert specializing in allocation-free async/await patterns, coroutine migration, and Unity-optimized asynchronous programming. Masters UniTask performance optimizations, cancellation handling, and memory-efficient async operations. Use PROACTIVELY for UniTask implementation, async optimization, or coroutine replacement.

8 stars

Best use case

unity-unitask is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

UniTask library expert specializing in allocation-free async/await patterns, coroutine migration, and Unity-optimized asynchronous programming. Masters UniTask performance optimizations, cancellation handling, and memory-efficient async operations. Use PROACTIVELY for UniTask implementation, async optimization, or coroutine replacement.

Teams using unity-unitask should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/unity-unitask/SKILL.md --create-dirs "https://raw.githubusercontent.com/creator-hian/claude-code-plugins/main/unity-plugin/skills/unity-unitask/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/unity-unitask/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How unity-unitask Compares

Feature / Agentunity-unitaskStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

UniTask library expert specializing in allocation-free async/await patterns, coroutine migration, and Unity-optimized asynchronous programming. Masters UniTask performance optimizations, cancellation handling, and memory-efficient async operations. Use PROACTIVELY for UniTask implementation, async optimization, or coroutine replacement.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# UniTask - High-Performance Async for Unity

## Overview

UniTask is a zero-allocation async/await library optimized for Unity, providing allocation-free asynchronous programming patterns superior to standard C# Task.

**Foundation Required**: `unity-csharp-fundamentals` (TryGetComponent, FindAnyObjectByType), `csharp-async-patterns` (Task, async/await), `unity-async` (Unity async context)

**Core Topics**:
- Allocation-free async/await patterns
- Coroutine to UniTask migration
- PlayerLoop-based execution model
- Memory pool management and GC pressure reduction
- Advanced cancellation and timeout handling
- Integration with Unity systems (Addressables, DOTween, etc.)

**Learning Path**: C# async basics → Unity async context → UniTask optimization → Production patterns

## Quick Start

### UniTask vs Task Performance

```csharp
// Standard Task (allocates memory)
public async Task<int> GetStandard()
{
    await Task.Delay(1000);
    return 42;
}

// UniTask (zero allocation)
public async UniTask<int> GetOptimized()
{
    await UniTask.Delay(1000);
    return 42;
}
```

### Basic Patterns

```csharp
// Frame-based delays
await UniTask.Yield();                    // Next frame
await UniTask.DelayFrame(10);            // Wait 10 frames
await UniTask.NextFrame();               // Explicit next frame

// Time-based delays
await UniTask.Delay(TimeSpan.FromSeconds(1));
await UniTask.WaitForSeconds(1f);

// Unity operations
await Resources.LoadAsync<Sprite>("icon").ToUniTask();
await SceneManager.LoadSceneAsync("Level1").ToUniTask();

// Cancellation
CancellationTokenSource cts = new CancellationTokenSource();
await SomeOperation(cts.Token);
```

## When to Use

### UniTask (This Skill)
- Zero-allocation critical paths (mobile, performance-critical scenarios)
- Memory-efficient async operations
- PlayerLoop timing control and customization
- Coroutine replacement for better performance
- Integration with Unity async operations

### Alternatives
- **unity-async skill**: General Unity async patterns, coroutines, Job System
- **Standard Task**: Cross-platform .NET code, non-performance-critical scenarios

## Reference Documentation

### [UniTask Fundamentals](references/unitask-fundamentals.md)
Core UniTask concepts and migration:
- UniTask vs Task performance characteristics
- Coroutine migration patterns
- PlayerLoop execution model
- Memory pool management
- Basic async operations

### [Performance Optimization](references/performance-optimization.md)
Advanced performance techniques:
- Allocation-free patterns
- GC pressure reduction
- PlayerLoop timing control
- Memory profiling with UniTask.Tracker
- Burst-compatible async patterns

### [Integration Patterns](references/integration-patterns.md)
Unity system integrations:
- Addressables async loading
- DOTween integration
- UnityWebRequest patterns
- UI event handling
- AsyncReactiveProperty usage

## Key Principles

1. **Zero-Allocation Focus**: UniTask eliminates allocations for async operations
2. **PlayerLoop Integration**: Tight Unity integration for optimal performance
3. **Always Support Cancellation**: Use `this.GetCancellationTokenOnDestroy()` for MonoBehaviour lifecycle
4. **Prefer UniTask over Task**: Better performance and Unity compatibility
5. **Profile Memory Usage**: Use UniTask.Tracker to monitor active tasks and memory

## Common Patterns

### Automatic Cancellation with MonoBehaviour

```csharp
public class Example : MonoBehaviour
{
    async UniTaskVoid Start()
    {
        // Auto-cancels when GameObject is destroyed
        await LoadData(this.GetCancellationTokenOnDestroy());
    }
}
```

### Parallel Operations

```csharp
// Execute multiple operations in parallel
(int result1, string result2, float result3) = await UniTask.WhenAll(
    Operation1(),
    Operation2(),
    Operation3()
);
```

### Timeout Handling

```csharp
CancellationTokenSource cts = new CancellationTokenSource();
cts.CancelAfterSlim(TimeSpan.FromSeconds(5)); // PlayerLoop-based

try
{
    await LongOperation(cts.Token);
}
catch (OperationCanceledException)
{
    Debug.Log("Operation timed out");
}
```

## Platform Considerations

- **WebGL**: Limited threading, UniTask provides frame-based async as primary pattern
- **Mobile**: Critical for battery optimization and memory efficiency
- **Desktop**: Full feature support with optimal performance

## Best Practices

1. **Use CancellationToken**: Always pass cancellation tokens, prefer `this.GetCancellationTokenOnDestroy()`
2. **Avoid async void**: Use `UniTaskVoid` for fire-and-forget operations
3. **PlayerLoop Optimization**: Use minimal PlayerLoop injection for better performance
4. **Profile with Tracker**: Monitor memory with `UniTask.Tracker` in editor
5. **Chain Operations**: Use `WhenAll`/`WhenAny` for parallel execution
6. **Thread Switching**: Use `SwitchToMainThread()`/`SwitchToThreadPool()` appropriately

## Integration with Other Skills

- **unity-async**: Provides foundation for Unity async patterns
- **unity-reactive**: AsyncReactiveProperty bridges UniTask with R3
- **unity-di**: UniTask works seamlessly with VContainer DI patterns
- **unity-performance**: UniTask reduces GC pressure significantly

Related Skills

unity-vcontainer

8
from creator-hian/claude-code-plugins

VContainer dependency injection expert specializing in IoC container configuration, lifecycle management, and Unity-optimized DI patterns. Masters dependency resolution, scoped containers, and testable architecture design. Use PROACTIVELY for VContainer setup, service registration, or SOLID principle implementation.

unity-unirx

8
from creator-hian/claude-code-plugins

UniRx (Reactive Extensions) library expert for legacy Unity projects. Specializes in UniRx-specific patterns, Observable streams, and ReactiveProperty. Use for maintaining existing UniRx codebases. For new projects, use unity-r3 skill instead.

unity-ui

8
from creator-hian/claude-code-plugins

Build and optimize Unity UI with UI Toolkit and UGUI. Masters responsive layouts, event systems, and performance optimization. Use for UI implementation, Canvas optimization, or cross-platform UI challenges.

unity-textmeshpro

8
from creator-hian/claude-code-plugins

TextMeshPro (TMPro) expert for Unity text rendering with advanced typography, performance optimization, and professional text effects. Masters font asset creation, dynamic fonts, rich text formatting, material presets, and text mesh optimization. Use PROACTIVELY for text rendering, font management, localization text, UI text performance, or text effects implementation.

unity-testrunner

8
from creator-hian/claude-code-plugins

Unity Test Framework CLI automation and test writing patterns. Masters batchmode execution, NUnit assertions, EditMode/PlayMode testing, and TDD workflows. Use PROACTIVELY for test automation, CI/CD pipelines, or test-driven development in Unity.

unity-r3

8
from creator-hian/claude-code-plugins

R3 (Reactive Extensions) library expert specializing in modern reactive programming patterns, event-driven architectures, and Observable streams. Masters R3-specific features, async enumerable integration, and Unity-optimized reactive patterns. Use PROACTIVELY for R3 implementation, reactive programming, or MVVM/MVP architecture.

unity-performance

8
from creator-hian/claude-code-plugins

Optimize Unity game performance through profiling, draw call reduction, and resource management. Masters batching, LOD, occlusion culling, and mobile optimization. Use for performance bottlenecks, frame rate issues, or optimization strategies.

unity-networking

8
from creator-hian/claude-code-plugins

Implement multiplayer games with Unity Netcode, Mirror, or Photon. Masters client-server architecture, state synchronization, and lag compensation. Use for multiplayer features, networking issues, or real-time synchronization.

unity-mobile

8
from creator-hian/claude-code-plugins

Optimize Unity games for mobile platforms with IL2CPP, platform-specific code, and memory management. Masters iOS/Android deployment, app size reduction, and battery optimization. Use for mobile builds, platform issues, or device-specific optimization.

unity-csharp-fundamentals

8
from creator-hian/claude-code-plugins

Unity C# fundamental patterns including TryGetComponent, SerializeField, RequireComponent, and safe coding practices. Essential patterns for robust Unity development. Use PROACTIVELY for any Unity C# code to ensure best practices.

unity-collection-pool

8
from creator-hian/claude-code-plugins

Unity Collection Pool expert for GC-free collection management using ListPool, DictionaryPool, HashSetPool, and ObjectPool. Masters memory optimization, pool sizing, and allocation-free patterns. Use PROACTIVELY for collection allocations, GC pressure reduction, temporary list/dictionary usage, or performance-critical code paths.

unity-async

8
from creator-hian/claude-code-plugins

Handle Unity's asynchronous programming patterns including coroutines, async/await, and Job System. Masters Unity's main thread restrictions and threading models. Use when guidance needed on Unity async operations, coroutine optimization, or parallel processing in Unity context.