SanderMertens /flecs
A fast entity component system (ECS) for C & C++
★ 8,845⑂ 632👁 78⑃ 1,539● 788▤ 66
+6
Daily
8,845
stars
632
forks
78
watchers
1,539
prs
788
issues
66
releases
README
!flecs
Flecs is a fast and lightweight Entity Component System that lets you build games and simulations with millions of entities (join the Discord!). Here are some of the framework's highlights:
- Fast and portable zero dependency C99 API
- Modern type-safe C++17 API that doesn't use STL containers
- First open source ECS with full support for Entity Relationships!
- Fast native support for hierarchies and prefabs
- Code base that builds in less than 5 seconds
- Runs in the browser without modifications with emscripten
- Cache friendly archetype/SoA storage that can process millions of entities every frame
- Automatic component registration that works out of the box across shared libraries/DLLs
- Write free functions with queries or run code automatically in systems
- Run games on multiple CPU cores with a fast lockless scheduler
- Verified on all major compilers and platforms with CI running more than 13000 tests
- Integrated reflection framework with JSON serializer and support for runtime components
- Unit annotations for components
- Powerful query language with support for joins and inheritance
- Statistics addon for profiling ECS performance
- A web-based UI for monitoring & controlling your apps:
To support the project, give it a star 🌟 !
What is an Entity Component System?
ECS is a way of organizing code and data that lets you build games that are larger, more complex and are easier to extend. Something is called an ECS when it:
- Has _entities_ that uniquely identify objects in a game
- Has _components_ which are datatypes that can be added to entities
- Has _systems_ which are functions that run for all entities matching a component _query_
For more information, check the ECS FAQ!
Show me the code!
C99 example:
c
typedef struct {
float x, y;
} Position, Velocity;
void Move(ecs_iter_t it) {
Position p = ecs_field(it, Position, 0);
Velocity v = ecs_field(it, Velocity, 1);
for (int i = 0; i count; i++) {
p[i].x += v[i].x;
p[i].y += v[i].y;
}
}
int main(int argc, char argv[]) {
ecs_world_t ecs = ecs_init();
ECS_COMPONENT(ecs, Position);
ECS_COMPONENT(ecs, Velocity);
ECS_SYSTEM(ecs, Move, EcsOnUpdate, Position, Velocity);
ecs_entity_t e = ecs_insert(ecs,
ecs_value(Position, {10, 20}),
ecs_value(Velocity, {1, 2}));
while (ecs_progress(ecs, 0)) { }
}
Same example in C++:
cpp
struct Position {
float x, y;
};
struct Velocity {
float x, y;
};
int main(int argc, char argv[]) {
flecs::world ecs;
ecs.system()
.each( {
p.x += v.x;
p.y += v.y;
});
auto e = ecs.entity()
.insert( {
p = {10, 20};
v = {1, 2};
});
while (ecs.progress()) { }
}
Projects using Flecs
If you have a project you'd like to share, let me know on Discord!
Tempest Rising
Territory Control 2
Polyzonia
Resistance is Brutal
Appulse
Rescue Ops: Wildfire
Age of Respair
FEAST
Gloam Vault
Antimatcher
Writ of Battle
Extermination ShoTop issues
#1317C++20 module support19 comments · 2024-08-20#478Incorrect memory alignment of components.16 comments · 2021-08-31#680Pluggable storages8 comments · 2022-03-18#714Stack overflow with two acyclic relations in opposite directions5 comments · 2022-05-04#1345Add support for component inheritance to the reflection framework4 comments · 2024-09-09#872Multi-threaded stats4 comments · 2022-11-30#2094Tick Source should be able to tick more than once per frame3 comments · 2026-05-14#326Allow for associating multiple queries with single system.3 comments · 2021-03-03
Discussions
#2143Error while try create function in flecs script1 comments · 2026-06-15#2131Loading models and other complex data during flecs world deserialization1 comments · 2026-06-11#2121How to gate systems by a global enum game state0 comments · 2026-06-03#1895Error when using world in different std::thread0 comments · 2025-12-19#1894Deserialize a component from a custom format1 comments · 2025-12-16#1885running script on system1 comments · 2025-12-03#1883confused with auto sync points1 comments · 2025-12-01#1737Separate Systems/Pipelines for Update and Draw cycles1 comments · 2025-07-26
Latest release
Flecs v4.2.0 v4.2.0 2026-11-04Release announcement https://ajmmertens.medium.com/flecs-4-2-is-out-09435e80fdd1 Release notes This version includes the following improvements: - [core] Flush stage commands in ecs_fini - [core] Detect WebAssembly targets other than Emscripten (thanks @andrewgazelka!) - [core] Default to Any term for observers without terms - [core] Rename (OnInstantiate, Override) trait to (OnInstantiate, Copy) - [core] Add ecs_ref_from_ptr() - [core] Lock tables for OnAdd/OnRemove hooks and observers - [core] Only allow DontFragment With targets on DontFragment components - [core] Reduce o