Arch ECS Documentation

repository·master·Indexed 21 days ago

https://github.com/genaray/arch

A high-performance, minimal Archetype & Chunks based Entity Component System (ECS) for C# designed for game development and data-oriented programming. It supports .NET Standard 2.1, .NET Core 6, and .NET 8, and is compatible with Unity and Godot. Key features include 16KB chunks for cache efficiency, multithreaded queries, and AOT friendliness.

Tokens
790
Snippets
2
Records
4
Agent score
33%

What's inside Arch

  1. Arch Core Features

    master

    Arch is a high-performance Archetype & Chunks based Entity Component System (ECS) designed for data-oriented programming. Key features include:

    • Archetypes & Chunks: Uses 16KB chunks for massive worlds.
    • Performance: Optimized for cache efficiency, iteration, and allocation speed; supports multithreaded queries.
    • API Flexibility: Provides both Generic and Non-Generic APIs, and supports Pure-ECS for maximum efficiency.
    • Data Operations: Supports Bulk/Batch entity operations, CommandBuffers, and Events.
    • Compatibility: AOT friendly; supports .NET Standard 2.1, .NET Core 6, and .NET 8 (compatible with Unity and Godot).
  2. Explore Arch Extensions

    master

    Several libraries extend Arch's functionality to reduce boilerplate or integrate with specific engines:

    • Arch.Extended: Adds tools and features to reduce boilerplate code.
    • Arch.Unity: Simplifies integration with the Unity engine.
    • Godot Entity Debugger: An entity debugger specifically for the Godot engine.
    • Stride Entity Debugger: An inspector/debugger for the Stride engine.
    • Zinc-Framework: A framework based on Arch that uses source generators to define entities declaratively.
  3. Quickstart: Create entities and run queries

    master

    Arch follows a minimal ECS pattern where you define components as record struct types, create a World, and use QueryDescription to iterate over entities with specific component combinations.

    To move entities based on velocity:

    1. Define component structs (e.g., Position, Velocity).
    2. Create a World using World.Create().
    3. Create entities with world.Create(...) passing component instances.
    4. Use world.Query with a QueryDescription to perform logic on entities matching your criteria.
    using Arch;
    
    // Components
    public record struct Position(float X, float Y);
    public record struct Velocity(float Dx, float Dy);
    
    // Create a world and an entity with position and velocity.
    using var world = World.Create();
    var adventurer = world.Create(new Position(0,0), new Velocity(1,1));
    
    // Enumerate all entities with Position & Velocity to move them
    var query = new QueryDescription().WithAll<Position,Velocity>();
    world.Query(in query, (Entity entity, ref Position pos, ref Velocity vel) => {
        pos.X += vel.Dx;
        pos.Y += vel.Dy;
        Console.WriteLine($"Moved adventurer: {entity.Id}"); 
    });