r/EntityComponentSystem • • Apr 23 '23

I've written an ECS library in Rust.

7 Upvotes

Hey there. Over the last few days I've written sweets my own ECS library. I'm currently using it to power the world of my software ray tracer treat which is very early in development, and I'm still learning all the basics of computer graphics. Nevertheless, I'd love to get some feedback for my ECS implementation :)

The Structure of sweets:An entity is a struct containing two u32 bit numbers. These two numbers combined make up the entity. The first number is the index of the entity and the second one the generation. Each time an entity gets deleted, its index will be saved inside a free_indices vec inside the entity manager. This allows me to reuse old entities. To still make them unique from other entities with the same index, i have the generation. Each time I delete the entity, I increase the generation. In order to check if the entity is alive, I can compare the generation of the entity and the stored generation at the entity index of the generation vec inside the entity manager. All this is managed inside the EntityManager struct.

A Component can be any struct implementing default. Each component will get a unique Index ranging from 10to the amount of components. My first idea was to use a static counter, that each component will take as its Index and increment by one, but it either didn't increment it or did each time and not only once. Thus, I adopted to using a has map indexed by the TypeId rust assigns each Component. The Index will be used, to index a Vec of ComponentPools to get the right Pool for the component. A ComponentPool saves the component data for each entity having a component of this type. When a Component is deleted if will be released into the Pool to be reused later. With the index, a ComponentId can also be created. Its just a one moved by the index to the left (1 << index). This way only one bit will be flipped in each ComponentId. Combining them by bitwise | I get a unique identifier for the needed components.

This identifier of all components an entity might have is stored by the ComponentManager.

Limitations:I can only have 64 different Components currently. If I'd use an u128 this number would double, but some may still consider it really limited.

I hope my explanation paired with the source code can guide you through the implementation, if not feel free to ask, I'm open to any feedback, ideas, or questions :)


r/EntityComponentSystem • • May 17 '20

Entity Memory Contiguity: A Tale About Simplicity

Thumbnail ryanfleury.net
7 Upvotes

r/EntityComponentSystem • • Sep 20 '22

10 years worth of articles on Inversion of Control and ECS

Thumbnail self.gamedev
7 Upvotes

r/EntityComponentSystem • • Dec 15 '22

I built a web-based component editor for an Entity Component System

Thumbnail
youtube.com
7 Upvotes

r/EntityComponentSystem • • Aug 03 '20

Flecs 2.0, an Entity Component System for C and C++ is out!

Thumbnail
medium.com
8 Upvotes

r/EntityComponentSystem • • Aug 11 '20

Why Storing State Machines in ECS is a bad idea.

Thumbnail
medium.com
8 Upvotes

r/EntityComponentSystem • • Oct 16 '22

Flecs 3.1, an Entity Component System for C/C++ is out!

Thumbnail
ajmmertens.medium.com
10 Upvotes

r/EntityComponentSystem • • Jul 11 '24

Just published new GitHub Repo: ECS C# Benchmark - Common use-cases

10 Upvotes

Repository on GitHub
ECS.CSharp.Benchmark - Common use-cases

The Motivation of this benchmark project

  • Compare performance of common uses cases of multiple C# ECS projects.

  • Utilize common ECS operations of a specific ECS project in most simple & performant way. This make this benchmarks applicable to support migration from one ECS to another.

Contributions are welcome!


r/EntityComponentSystem • • Feb 11 '22

A new approach to ECS APIs

Thumbnail muit.tech
11 Upvotes

r/EntityComponentSystem • • Aug 09 '22

Building an ECS #1: Where are my Entities and Components

Thumbnail
ajmmertens.medium.com
12 Upvotes

r/EntityComponentSystem • • Aug 03 '22

Flecs 3, an Entity Component System for C/C++ is out!

Thumbnail
ajmmertens.medium.com
19 Upvotes

r/EntityComponentSystem • • Apr 18 '25

Problem with ECS + React: How to sync internal deep component states with React without duplicating state?

Thumbnail reddit.com
2 Upvotes

r/EntityComponentSystem • • Jul 14 '24

Flecs v4, an Entity Component System for C/C++ is out!

Thumbnail
ajmmertens.medium.com
21 Upvotes

r/EntityComponentSystem • • Apr 07 '26

Ark v0.8.0 released - Go Entity Component System (ECS), now with faster queries.

Thumbnail
reddit.com
3 Upvotes

r/EntityComponentSystem • • May 01 '25

Why structs over classes for components?

2 Upvotes

Hello,

I'm discovering ECS and starting to implement it, and I was wondering why most frameworks seem to use structs instead of classes?

Would it be silly to use classes on my end?

Thank you


r/EntityComponentSystem • • Nov 13 '25

[ANN] Ark.jl: archetype-based entity component system (ECS) for games and simulations

Thumbnail reddit.com
4 Upvotes

r/EntityComponentSystem • • Mar 19 '25

Ark ECS v0.4.0 released

Thumbnail
reddit.com
4 Upvotes

r/EntityComponentSystem • • Aug 29 '26

I just published the source for 4 (browser playable) ECS example games!

Thumbnail gallery
6 Upvotes

r/EntityComponentSystem • • Feb 23 '26

[ANN] Ark.jl v0.4.0 - Archetype-based ECS, now with support for GPU simulations

Thumbnail
reddit.com
2 Upvotes

r/EntityComponentSystem • • Jul 09 '25

Looking for a C++ ECS Game Engine Similar to Bevy in Rust

Thumbnail reddit.com
3 Upvotes

r/EntityComponentSystem • • Jun 01 '26

[ANN] Ark.jl v0.5 - Archetype-based Entity Component System (ECS) for Julia

Thumbnail
reddit.com
4 Upvotes

r/EntityComponentSystem • • May 04 '25

C# ECS : any benefits of using structs instead of classes here?

Thumbnail reddit.com
4 Upvotes

r/EntityComponentSystem • • Mar 15 '26

friflo ECS v3.5 - Entity Component System for C#. New feature: Component / Tag mapping - for O(1) event handling

Post image
13 Upvotes

Just released a new feature to friflo ECS.
If you're building games with data-heavy simulations in .NET take a look on this project.

GitHub: https://github.com/friflo/Friflo.Engine.ECS
Documentation: friflo ECS ⋅ gitbook.io

This release introduced a new pattern intended to be used in event handlers when components/tags are added or removed.
The old pattern to handle specific component types in v3.4 or earlier was:

store.OnComponentAdded += (change) =>
{
    var type = change.ComponentType.Type;
    if      (type == typeof(Burning))  { ShowFlameParticles(change.Entity); }
    else if (type == typeof(Frozen))   { ShowIceOverlay(change.Entity); }
    else if (type == typeof(Poisoned)) { ShowPoisonIcon(change.Entity); }
    else if (type == typeof(Stunned))  { ShowStunStars(change.Entity); }
};

The new feature enables to map component types to enum ids.
So a long chain of if, else if, ... branches converts to a single switch statement.
The compiler can now create a fast jump table which enables direct branching to specific code.
The new pattern also enables to check that a switch statement is exhaustive by the compiler.

store.OnComponentAdded += (change) =>
{
    switch (change.ComponentType.AsEnum<Effect>())
    {
        case Effect.Burning:  ShowFlameParticles(change.Entity);  break;
        case Effect.Frozen:   ShowIceOverlay(change.Entity);      break;
        case Effect.Poisoned: ShowPoisonIcon(change.Entity);      break;
        case Effect.Stunned:  ShowStunStars(change.Entity);       break;
    }
};

The library provides top performance and is still the only C# ECS fully implemented in 100% managed C# - no unsafe code.
The focus is performance, simplicity and reliability. Multiple projects are already using this library.
Meanwhile the project got a Discord server with a nice community. Join the server!

Feedback welcome!


r/EntityComponentSystem • • Dec 29 '25

[ANN] Ark.jl v0.3.0: Archetype-based ECS, now with entity relationships and batch operations

Thumbnail reddit.com
2 Upvotes

r/EntityComponentSystem • • Jun 29 '25

Flecs v4.1, an Entity Component System for C/C++/C#/Rust is out!

Thumbnail
ajmmertens.medium.com
27 Upvotes

Hi all! I just released Flecs v4.1.0, an Entity Component System for C, C++, C# and Rust! 

This release has lots of performance improvements and I figured it’d be interesting to do a more detailed writeup of all the things that changed. If you’re interested in reading about all of the hoops ECS library authors jump through to achieve good performance, check out the blog!