unity-async

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.

8 stars

Best use case

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

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.

Teams using unity-async 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-async/SKILL.md --create-dirs "https://raw.githubusercontent.com/creator-hian/claude-code-plugins/main/unity-plugin/skills/unity-async/SKILL.md"

Manual Installation

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

How unity-async Compares

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

Frequently Asked Questions

What does this skill do?

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.

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

# Unity Async Patterns

## Overview

Unity-specific async patterns extending foundational C# async/await concepts.

**Foundation Required**: `unity-csharp-fundamentals` (TryGetComponent, FindAnyObjectByType, null-safe coding)

**Core Topics**:
- Coroutines and yield instructions
- async/await with Unity main thread constraints
- Unity Job System and Burst compiler
- Thread safety and marshaling
- Addressables and UnityWebRequest integration

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

## Quick Start

### Three Unity Async Approaches

```csharp
// 1. Coroutine (Unity-specific, frame-based)
IEnumerator LoadDataCoroutine()
{
    yield return new WaitForSeconds(1f);
    UnityWebRequest request = UnityWebRequest.Get(url);
    yield return request.SendWebRequest();
    ProcessData(request.downloadHandler.text);
}

// 2. Async/Await (C# standard + Unity constraints)
async Task<string> LoadData(CancellationToken ct)
{
    await Task.Delay(1000, ct);
    using UnityWebRequest request = UnityWebRequest.Get(url);
    await request.SendWebRequest();
    return request.downloadHandler.text;
    // Unity auto-marshals to main thread
}

// 3. Job System (parallel data processing)
[BurstCompile]
struct VelocityJob : IJobParallelFor
{
    [ReadOnly] public NativeArray<Vector3> velocities;
    public NativeArray<Vector3> positions;
    public float deltaTime;

    public void Execute(int index)
    {
        positions[index] += velocities[index] * deltaTime;
    }
}
```

## When to Use

### Unity Async (This Skill)
- Frame-based timing and Unity API integration
- Standard async/await with Unity constraints
- Job System parallelization
- Main thread restrictions and solutions

### Specialized Skills
- **unity-unitask**: Zero-allocation async, memory-critical scenarios
- **unity-r3**: Event streams, MVVM/MVP, reactive state management

## Reference Documentation

### Unity-Specific Extensions

**[Unity Async Best Practices](references/unity-async-best-practices.md)**
- Coroutines vs async/await decision framework
- Main thread restrictions and solutions
- Job System usage patterns
- MonoBehaviour lifecycle integration

**[Coroutine Patterns](references/coroutine-patterns.md)**
- yield return variations
- Coroutine chaining and composition
- Custom yield instructions
- Performance considerations

**[Unity Threading Guide](references/unity-threading.md)**
- Main thread vs background threads
- UnityMainThreadDispatcher patterns
- Job System and Burst compiler
- Thread-safe data structures (NativeArray, NativeContainer)

## Key Principles

1. **Main Thread Only**: Unity APIs require main thread
2. **Coroutines for Frames**: Frame-based operations use coroutines
3. **Job System for Parallelism**: CPU-intensive data processing
4. **UniTask for Performance**: Zero-allocation critical paths
5. **R3 for Reactive**: Complex event streams and data binding

## Common Patterns

### Frame Timing
```csharp
yield return null;                    // Next frame
yield return new WaitForEndOfFrame(); // After rendering
yield return new WaitForFixedUpdate(); // Physics update
```

### Async Resource Loading
```csharp
AsyncOperation asyncLoad = SceneManager.LoadSceneAsync("Scene");
while (!asyncLoad.isDone)
{
    float progress = Mathf.Clamp01(asyncLoad.progress / 0.9f);
    yield return null;
}
```

### Addressables Integration
```csharp
AsyncOperationHandle<GameObject> handle = Addressables.LoadAssetAsync<GameObject>("AssetKey");
await handle.Task;
GameObject prefab = handle.Result;
```

## Platform Considerations

- **WebGL**: No threading, coroutines primary, Job System unavailable
- **Mobile**: Battery optimization critical, limit thread count
- **Desktop**: Full threading support, higher performance budgets

## Agent Delegation

```
Unity Async Needs
├── Frame timing → unity-async (coroutines)
├── Standard async → unity-async (async/await)
├── Parallel data → unity-async (Job System)
├── Zero-allocation → unity-unitask skill
└── Reactive patterns → unity-r3 skill
```

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-unitask

8
from creator-hian/claude-code-plugins

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.

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.