Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
D

DragonECS

> DevOps
Open source

Pure C# Entity Component System framework

333 stars0 likes5 views
WebsiteGitHub

About

Pure C# Entity Component System framework

DragonECS - C# Entity Component System Framework

Readme Languages:







  
    

    Русский
    


  
    

    English
    


  
    

    中文

The ECS Framework aims to maximize usability, modularity, extensibility and performance for dynamic entity changes, without code generation or external dependencies. Inspired by LeoEcs Lite.

[!Note] Have questions or want to stay updated on development? Join our community! -> Feedback

Table of Contents

  • Installation
  • Extensions
  • Quick Start
  • Basic Concepts
    • Entity
    • Component
    • System
  • Framework Concepts
    • Pipeline
      • Building
      • Dependency Injection
      • Modules
      • Sorting
    • Processes
    • World
    • Pool
    • Mask
    • Aspect
    • Queries
    • Collections
    • ECS Root
  • Multithreading
  • Debug
    • Meta Attributes
    • EcsDebug
    • Profiling
  • Define Symbols
  • Framework Extension Tools
    • World Components
    • Configs
  • Projects powered by DragonECS
  • Extensions
  • FAQ
  • Feedback
  • License

Installation

Versioning semantics - Open

Environment

Requirements:

  • Minimum C# version: 7.3.

Supported:

  • NativeAOT;
  • Game engines with C#: Unity, Godot, MonoGame, etc.

Tested with:

  • Unity: Minimum version 2021.2.0.

Unity Installation

It is also recommended to install the Unity engine integration extension Unity integration

  • Unity package

Installation as a Unity package is supported by adding the Git URL in PackageManager:

https://github.com/DCFApixels/DragonECS.git

Or add the package entry to Packages/manifest.json:

"com.dcfa_pixels.dragonecs": "https://github.com/DCFApixels/DragonECS.git",
  • As source code

The framework sources can be copied directly into the project.

Extensions

  • Integrations:
    • Unity
    • Godot
  • Packages:
    • Dependency autoinjections
    • Classic C# multithreading
    • Recursivity
    • Hybrid
    • Graphs
  • Utilities:
    • Simple syntax
    • EcsRefPool
    • Timers
    • One-Frame Components
    • Code Templates for IDE and for Unity

*Your extension? Extensions for DragonECS are welcome, you can share it here.

Quick Start

These two scripts bring together the basic DragonECS workflow: create a world, build a pipeline, inject dependencies, run systems, query entities by an aspect, edit components through pools, and release resources.

EcsRoot.cs

…

MovementSystem.cs

…

Basic Concepts

Entity

Container for components. Two identifier types are used to reference entities:

  • int - short-lived identifier, valid within a single tick. Not recommended for long-term storage;
  • entlong - long-term identifier that includes a generation tag, making it unique across entity lifetimes. Suitable for long-term storage.
csharp
// Creating a new entity in the world.
int entityID = _world.NewEntity();

// Deleting an entity.
_world.DelEntity(entityID);

// Copying components from one entity to another.
_world.CopyEntity(entityID, otherEntityID);

// Cloning an entity.
int newEntityID = _world.CloneEntity(entityID);

Working with entlong

csharp
// Convert int to entlong.
entlong entity = _world.GetEntityLong(entityID);
// or
entlong entity = (_world, entityID);

// Check that the entity is still alive.
if (entity.IsAlive) { }

// Converting entlong to int. Throws an exception if the entity no longer exists.
int entityID = entity.ID;
// or
var (entityID, world) = entity;
 
// Converting entlong to int. Returns true and the int identifier if the entity is still alive.
if (entity.TryGetID(out int entityID)) { }

Entities cannot exist without components. Removing the last component automatically deletes the entity along with it.

Component

Data for entities.

csharp
// IEcsComponent components are stored in regular storage.
struct Health : IEcsComponent
{
    public float health;
    public int armor;
}
// Components with IEcsTagComponent are stored in tag-optimized storage.
struct PlayerTag : IEcsTagComponent {}

System

Represents the core logic defining entity behaviors. Systems are implemented as user-defined classes that implement one or more process interfaces. Key processes include:

csharp
class SomeSystem : IEcsPreInit, IEcsInit, IEcsRun, IEcsDestroy
{
    // Called once during EcsPipeline.Init() and before IEcsInit.Init().
    public void PreInit () { }
    
    // Called once during EcsPipeline.Init() and after IEcsPreInit.PreInit().
    public void Init ()  { }
    
    // Called each time during EcsPipeline.Run().
    public void Run () { }
    
    // Called once during EcsPipeline.Destroy().
    public void Destroy () { }
}

For implementing additional processes, refer to the Processes section.

Framework Concepts

Pipeline

Container and engine of systems. Responsible for setting up the system call queue, providing mechanisms for communication between systems, and dependency injection. Implemented as the EcsPipeline class.

Building

Builder is responsible for building the pipeline. Systems are added to the Builder, and the pipeline is built at the end. Example:

csharp
EcsPipeline pipeline = EcsPipeline.New() // Creates a pipeline builder.
    // Adds System1 to the systems queue.
    .Add(new System1())
    // Adds System2 to the queue after System1.
    .Add(new System2())
    // Adds System3 to the queue after System2, as a unique instance.
    .AddUnique(new System3())
    // Completes the pipeline building and returns its instance.
    .Build(); 
pipeline.Init(); // Initializes the pipeline.
csharp
class SomeSystem : IEcsRun, IEcsPipelineMember
{
    // Gets the pipeline instance to which the system belongs.
    public EcsPipeline Pipeline { get ; set; }

    public void Run () { }
}

For simultaneous building and initialization, use Builder.BuildAndInit().

Dependency Injection

The framework implements dependency injection for systems. Injection process occurs during pipeline initialization and injects data passed to the Builder.

Built-in Dependency injection is optional.

…

Modules

Groups of systems that implement a common feature can be grouped into modules and added to the Pipeline.

csharp
using DCFApixels.DragonECS;
class Module1 : IEcsModule 
{
    public void Import(EcsPipeline.Builder b) 
    {
        b.Add(new System1());
        b.Add(new System2());
        b.AddModule(new Module2());
        // ...
    }
}
csharp
EcsPipeline pipeline = EcsPipeline.New()
    // ...
    .AddModule(new Module1())
    // ...
    .BuildAndInit();

Sorting

To manage system order in the pipeline regardless of addition order, use Layers and Sorting Order.

Layers

Queues of systems can be segmented into layers. A layer defines a position in the queue for inserting systems. For example, to insert a system at the end of the queue regardless of where it is added, add it to the EcsConsts.END_LAYER layer.

csharp
const string SOME_LAYER = nameof(SOME_LAYER);
EcsPipeline pipeline = EcsPipeline.New()
    // ...
    // Inserts a new layer before the end layer EcsConsts.END_LAYER
    .Layers.Add(SOME_LAYER).Before(EcsConsts.END_LAYER)
    // Inserts SOME_LAYER_2 layer at the position after EcsConsts.BASIC_LAYER
    .Layers.Add(SOME_LAYER).After(EcsConsts.BASIC_LAYER)
    // System SomeSystem will be added to the SOME_LAYER layer
    .Add(new SomeSystem(), SOME_LAYER) 
    // ...
    .BuildAndInit();

The built-in layers are arranged in the following order:

  • EcsConsts.PRE_BEGIN_LAYER
  • EcsConsts.BEGIN_LAYER
  • EcsConsts.BASIC_LAYER (Systems are added here if no layer is specified during addition)
  • EcsConsts.END_LAYER
  • EcsConsts.POST_END_LAYER

Sorting Order

The sort order integer value is used to sort systems within a layer. By default, systems are added with sortOrder = 0.

csharp
EcsPipeline pipeline = EcsPipeline.New()
    // ...
    // System SomeSystem will be inserted into the layer EcsConsts.BEGIN_LAYER 
    // and placed after systems with sortOrder less than 10.
    .Add(new SomeSystem(), EcsConsts.BEGIN_LAYER, 10)
    // ...
    .BuildAndInit();

Processes

Processes are queues of systems that implement a common interface, such as IEcsRun. Runners are used to start processes. Built-in processes are started automatically; custom processes can be implemented.

Built-in processes

  • IEcsPreInit, IEcsInit, IEcsRun, IEcsDestroy - lifecycle processes of EcsPipeline.
  • IEcsInject - Dependency Injection processes.
  • IOnInitInjectionComplete - Similar to the Dependency Injection process, but signals completion of initialization injection.

Custom Processes

To add a new process, create an interface inheriting from IEcsProcess and create a runner for it. A runner is a class that implements the process interface and inherits from EcsRunner. Example:

csharp
// Process interface.
interface IDoSomethingProcess : IEcsProcess
{
    void Do();
}
// Runner implementation. An example of implementation can also be seen in built-in processes.
sealed class DoSomethingProcessRunner : EcsRunner, IDoSomethingProcess
{
    public void Do() 
    {
        foreach (var item in Process) item.Do();
    }
}
csharp
// Adding the runner when creating the pipeline
_pipeline = EcsPipeline.New()
    //...
    .AddRunner()
    //...
    .BuildAndInit();

// Running the runner if it was added
_pipeline.GetRunner().Do();

// or if the runner was not added (calling GetRunnerInstance will also add the runner to the pipeline).
_pipeline.GetRunnerInstance().Do();

Advanced Implementation of a Runner

…

Runner requirements:

  • Inheritance from EcsRunner must be direct.
  • A runner may only contain one interface (excluding IEcsProcess).
  • The inheriting class of EcsRunner must also implement the T interface.

World

A container for entities and components.

csharp
// Creating an instance of the world.
_world = new EcsDefaultWorld();
// Creating and deleting an entity as shown in the Entities section.
var e = _world.NewEntity();
_world.DelEntity(e);

NOTICE: Call EcsWorld.Destroy() on the world instance when it is no longer needed to release resources. Otherwise it will remain in memor

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

C#csharpdragon-ecsdragonecsecs

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
CategoryDevOps
PricingOpen source

> Related tools

D
Docker
容器化平台,标准化应用交付
G
GitHub Actions
GitHub 原生 CI/CD 工作流
N
Nginx
高性能 Web 服务器与反向代理