agentleFS
Common-kaCommon-ka/ai-agent-unity-rules/.cursor/rules/unity-ecs.mdc

ai-agent-unity-rules / rules

Cursor rule40 starsChanged 12 months agoMITView on GitHub

DOTS, ECS, Job System, Burst, ISystem, IJobEntity

The file

We split this unity-ecs.mdc into the rules it gives an agent

2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Follow Microsoft Naming Conventions: Use PascalCase for public fields in Jobs and Components.

    line 13
  2. Very specific:

    Use this pattern when processing raw memory (NativeArray) outside of the ECS framework.

    line 77

≈ “Common” is an estimate: at least 1 in 5 of the 6,668 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
unity-ecs.mdc
---
description: "DOTS, ECS, Job System, Burst, ISystem, IJobEntity"
alwaysApply: false
---

# Unity ECS & DOTS (Unity 6.2+)

## Core Principles

1.  **Prefer `ISystem` (struct)** over `SystemBase` (class) to avoid GC overhead.
2.  **Always use `[BurstCompile]`** for Systems and Jobs to unlock native performance.
3.  **Use `IJobEntity`** for component iteration; it handles chunking and multithreading automatically.
4.  **Follow Microsoft Naming Conventions**: Use **PascalCase** for public fields in Jobs and Components.

## Entity Component System

### 1. Component Data
```
using Unity.Entities;
using Unity.Mathematics;

public struct MovementSpeed : IComponentData
{
    public float Value;
}
```

### 2. System (ISystem + IJobEntity)
This is the modern standard. It separates data iteration (Job) from the system lifecycle (System).

```
using Unity.Entities;
using Unity.Transforms;
using Unity.Burst;
using Unity.Mathematics;

[BurstCompile]
partial struct MovementSystem : ISystem
{
    [BurstCompile]
    public void OnCreate(ref SystemState state)
    {
        // Prevents the system from running if no entities have MovementSpeed
        state.RequireForUpdate<MovementSpeed>();
    }

    [BurstCompile]
    public void OnUpdate(ref SystemState state)
    {
        // Pass delta time into the job
        float deltaTime = SystemAPI.Time.DeltaTime;

        // Schedule the job to run in parallel across available worker threads
        new MoveJob
        {
            DeltaTime = deltaTime
        }.ScheduleParallel();
    }
}

// The Source Generator automatically creates the optimized chunk iteration code for this job
[BurstCompile]
partial struct MoveJob : IJobEntity
{
    public float DeltaTime;

    // Use 'in' for read-only data to improve performance
    private void Execute(ref LocalTransform transform, in MovementSpeed speed)
    {
        transform.Position += new float3(0, speed.Value * DeltaTime, 0);
    }
}
```

## Job System (Native Arrays)

Use this pattern when processing raw memory (`NativeArray`) outside of the ECS framework.

```
using Unity.Jobs;
using Unity.Collections;
using Unity.Burst;
using Unity.Mathematics;

[BurstCompile]
public struct VelocityJob : IJobParallelFor
{
    // Microsoft Style: Public fields should be PascalCase
    public NativeArray<float3> Velocity;
    
    [ReadOnly] 
    public NativeArray<float3> Acceleration;
    
    public float DeltaTime;
    
    public void Execute(int index)
    {
        Velocity[index] += Acceleration[index] * DeltaTime;
    }
}
```

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.