Skip to content

KenseiECSSparse-set ECS for Unity and .NET

Lightweight Entity Component System with O(1) component access, reactive filters and zero-allocation iteration.

At a glance ​

Components are plain structs. Systems declare what they need with attributes, and the source generator writes their Init.

csharp
partial class MoveSystem : IRunSystem {
    [Inc(typeof(Position), typeof(Velocity))] [Exc(typeof(Frozen))]
    Filter _moving;
    [Pool] ComponentPool<Position> _positions;
    [Pool] ComponentPool<Velocity> _velocities;

    public void Run(World world) {
        foreach (int e in _moving) {
            ref var pos = ref _positions.Get(e);
            ref var vel = ref _velocities.Get(e);
            pos.X += vel.X;
            pos.Y += vel.Y;
        }
    }
}
csharp
struct Position : IComponent { public float X, Y; }
struct Velocity : IComponent { public float X, Y; }
struct Frozen : IComponent { }
csharp
var world = new World();
var systems = new SystemsRunner(world)
    .Add(new MoveSystem());
systems.Init();               // generated Init fills the fields

var entity = world.CreateEntity(new Position());
world.Add(entity, new Velocity { X = 1, Y = 2 });

systems.Run();                // once per frame

Walk through a complete program in the Quick Start, see how it compares in the benchmarks and against other ECS frameworks, or browse the API reference.

See it run ​

Horde at three minutes: thousands of enemies and the ECS inspector with per-system timings

Horde is a survivors-like game built on KenseiECS that runs in your browser on .NET WebAssembly. The horde grows to thousands of enemies; the stress slider pushes the world past 20,000 live entities.

  • 22 systems, each showing one feature of the library
  • An ECS inspector with every system's time per frame, filter and pool sizes
  • Toggle systems at runtime and watch the game react