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#…
by j4flmao★ 47 GitHub stars
Install unity-csharp in Claude Code & Claude Desktop
Sign up to install this skill
Create a free account to reveal the install command and save the skill to your library.
- Reveal the one-line install command
- Save skills to your synced library
- Get notified when skills update
About this skill
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.
ChangeVersionper-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, orNativeParallelHashMap<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(notList<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
Allowed tools
Tools this skill is permitted to call.
No restriction — this skill can use any tool.
FAQ
What does the unity-csharp skill do?
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).
How do I install the unity-csharp skill?
Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.
Does the unity-csharp skill run scripts?
No, this skill is instructions only (SKILL.md) with no executable scripts.
Related skills
mcp-builder
AnthropicGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
claude-api
AnthropicReference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
algorithmic-art
AnthropicCreating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
mcp-integration
AnthropicThis skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…