Command Palette

Search for a command to run...

Назад к скиллам
скилл № 02242

unity-csharp

Use when the user asks about Unity DOTS, Unity ECS with Entities, ISystem, IJobEntity, Burst jobs, the C# Job System, NativeArray or GC-free Unity C#…

БесплатноБез исполняемых скриптов
j4flmaoот j4flmao★ 47 звёзд на GitHub

Установить unity-csharp в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Об этом скилле

Unity Data-Oriented Technology Stack (DOTS) & C# Mechanics

Purpose

This skill covers Unity's data-oriented stack (ECS, Job System, Burst) and the C# practices that make Unity code fast and correct.

Agent Protocol

Trigger

"unity dots", "unity ecs", "unity entities", "ISystem", "IJobEntity", "burst compiler", "unity job system", "unity c# performance".

Input Context

  • Unity version and Entities package version
  • MonoBehaviour, hybrid or pure ECS
  • Performance symptom (profiler capture if available)

Output Artifact

C# systems/jobs and authoring code. No file unless requested.

Response Format

Unity: {version}  Entities: {version}
System: {name, query, read/write}
Code: {snippet}
Verify: {Profiler / Burst inspector / Entities hierarchy}

1. Why DOTS: The OOP-Based Entry Points

Unity's classic MonoBehaviour model is object-oriented: each Behaviour instance owns its fields, script lifecycle callbacks run per frame, and objects reference each other. For 10k+ entities, per-object Update() incurs:

  • A virtual-call-like dispatch per object per frame.
  • Arbitrary memory layout → cache misses.
  • Heap fragmentation from per-frame allocation.

DOTS replaces this with contiguous data and systems-in-a-loop.

2. ECS Model in Unity

Packages: Entities 1.x on Unity 6.0-6.3 (com.unity.entities from the Package Manager); from Unity 6.4 Entities, Collections and Mathematics ship as core packages whose version matches the Editor. Code below uses the current ISystem + SystemAPI style (SystemBase Entities.ForEach lambdas are obsolete since Entities 1.4).

2.1 Entities, Components, Systems

// Component: struct, blittable, data-only
public struct Velocity : IComponentData {
    public float3 Linear;
    public float Angular;
}

// System: logic over queries
[BurstCompile]
public partial struct MoveSystem : ISystem {
    [BurstCompile]
    public void OnUpdate(ref SystemState state) {
        var dt = SystemAPI.Time.DeltaTime;
        foreach (var (tf, v) in SystemAPI.Query<RefRW<LocalTransform>, RefRO<Velocity>>()) {
            tf.ValueRW.Position += v.ValueRO.Linear * dt;
        }
    }
}

2.2 Archetypes & Chunks (Storage)

  • Archetype: unique set of component types. An entity's archetype determines its storage.
  • Chunk: a 16 KB block of memory holding entities of one archetype in SoA form.
Chunk 0 [Archetype: LocalTransform+Velocity ]
  Transform array: | t0 | t1 | t2 | ... | (contiguous)
  Velocity  array: | v0 | v1 | v2 | ... | (contiguous)
  • Iteration of a query walks matching chunks, so the CPU streams compact arrays into L1/L2.
  • ChangeVersion per-chunk tracks modification for change-detect systems.

2.3 Structural Changes (Command Buffers)

Adding/removing components moves the entity to another archetype (memcpy of affected fields). Doing this mid-iteration invalidates chunk iteration → use EntityCommandBuffer:

EntityCommandBuffer ecb = new EntityCommandBuffer(Allocator.Temp);
// queue AddComponent / SetComponent / DestroyEntity
ecb.Playback(state.EntityManager);

Rules: never call EntityManager.AddComponent inside ScheduleParallel jobs; always buffer.

3. The C# Job System

3.1 IJobEntity / IJobChunk

[BurstCompile]
public partial struct DamageJob : IJobEntity {
    public float Damage;
    void Execute(ref Health health) { health.Value -= Damage; }
}

var handle = new DamageJob { Damage = 5f }.Schedule(state.Dependency);
state.Dependency = handle;   // chain dependencies
  • Jobs run on worker threads; dependencies serialize through JobHandle.
  • Declare access precisely: in/RefRO<T> and [ReadOnly] for reads, ref/RefRW<T> for writes. This lets the job scheduler run readers in parallel and the safety system catch races. [DisableContainerSafetyRestriction] turns those checks off — use only with a written proof of disjoint access.

3.2 ParallelFor

// IJobEntity: chunks are distributed across worker threads
state.Dependency = new DamageJob { Damage = 5f }.ScheduleParallel(state.Dependency);
  • Each entity is processed by exactly one thread, so writing to the entity's own components is safe.
  • Cross-entity writes need EntityCommandBuffer.ParallelWriter (pass [ChunkIndexInQuery] int sortKey), NativeQueue<T>.ParallelWriter, or NativeParallelHashMap<K,V>.ParallelWriter; or write per-thread partial results and reduce afterwards.

4. Burst Compiler

  • Converts IL → native via LLVM. Uses SIMD automatically from SoA iteration.
  • Requires [BurstCompile] + job code to be Burst-compatible:
    • No managed references, no allocations, no strings in hot jobs.
    • Use float3, FixedString, NativeArray (not List<T>).
  • [BurstCompile(CompileSynchronously = true)] makes the Editor wait for Burst instead of running managed code first (useful for benchmarks); players are always AOT-compiled.

4.1 Burst-Compatible Data Types

| Use | Avoi

Полный SKILL.md на GitHub

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл unity-csharp?

Use when the user asks about Unity DOTS, Unity ECS with Entities, ISystem, IJobEntity, Burst jobs, the C# Job System, NativeArray or GC-free Unity C#. Produces Entities, Jobs and Burst code with correct safety rules. Not for general Unity project architecture (use unity) or engine-agnostic ECS design (use ecs-pattern).

Как установить скилл unity-csharp?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл unity-csharp запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить unity-csharp с