Convert Figma logo to code with AI

sschmid logoEntitas

Entitas is a super fast Entity Component System (ECS) Framework specifically made for C# and Unity

7,081
1,105
7,081
100

Top Related Projects

6,226

A fast entity component system (ECS) for C & C++

9,998

Gaming meets modern C++ - a fast and reliable entity component system (ECS) and much more

2,484

Specs - Parallel ECS

Quick Overview

Entitas is a powerful Entity Component System (ECS) framework for C# and Unity. It provides a fast and easy-to-use architecture for game development, focusing on composition over inheritance and promoting clean, modular code.

Pros

  • High performance due to its efficient data-oriented design
  • Encourages clean, modular, and easily maintainable code structure
  • Extensive documentation and active community support
  • Integrates well with Unity, providing editor tools and visual debugging

Cons

  • Steep learning curve for developers new to ECS architecture
  • Can be overkill for small, simple projects
  • Requires a shift in thinking from traditional object-oriented programming
  • May introduce additional complexity in certain scenarios

Code Examples

  1. Creating an entity and adding components:
public class Player : IComponent {}
public class Position : IComponent {
    public float x;
    public float y;
}

// In your system or game logic
var entity = context.CreateEntity();
entity.AddComponent(new Player());
entity.AddComponent(new Position { x = 10, y = 20 });
  1. Querying entities with specific components:
// Get all entities with both Player and Position components
var players = context.GetGroup(Matcher<GameEntity>.AllOf(GameMatcher.Player, GameMatcher.Position));

foreach (var player in players) {
    var position = player.position;
    // Do something with the player's position
}
  1. Reactive system example:
public class MoveSystem : ReactiveSystem<GameEntity> {
    public MoveSystem(IContext<GameEntity> context) : base(context) {}

    protected override ICollector<GameEntity> GetTrigger(IContext<GameEntity> context) {
        return context.CreateCollector(GameMatcher.Position);
    }

    protected override bool Filter(GameEntity entity) {
        return entity.hasPosition && entity.hasVelocity;
    }

    protected override void Execute(List<GameEntity> entities) {
        foreach (var e in entities) {
            e.position.value += e.velocity.value * Time.deltaTime;
        }
    }
}

Getting Started

  1. Install Entitas via Unity Package Manager or NuGet for non-Unity projects.
  2. Create your components as C# classes implementing IComponent.
  3. Define your systems by extending ReactiveSystem<T> or IExecuteSystem.
  4. Set up your contexts and systems in your game initialization:
public class GameController : MonoBehaviour {
    Systems _systems;

    void Start() {
        var contexts = Contexts.sharedInstance;
        _systems = new Feature("Game Systems")
            .Add(new MoveSystem(contexts.game))
            .Add(new OtherSystem(contexts.game));
    }

    void Update() {
        _systems.Execute();
    }
}
  1. Use the Entitas code generator to generate boilerplate code for your components and contexts.

Competitor Comparisons

6,226

A fast entity component system (ECS) for C & C++

Pros of flecs

  • Written in C, offering better performance and lower memory footprint
  • Supports both C and C++, providing flexibility for different projects
  • More actively maintained with frequent updates and improvements

Cons of flecs

  • Steeper learning curve due to its more complex architecture
  • Less Unity-specific features compared to Entitas
  • Documentation can be overwhelming for beginners

Code Comparison

Entitas (C#):

public class MovementSystem : IExecuteSystem {
    public void Execute() {
        foreach (var e in _group.GetEntities()) {
            var position = e.position;
            var velocity = e.velocity;
            position.value += velocity.value * Time.deltaTime;
        }
    }
}

flecs (C):

void Move(ecs_iter_t *it) {
    Position *p = ecs_field(it, Position, 1);
    Velocity *v = ecs_field(it, Velocity, 2);
    for (int i = 0; i < it->count; i++) {
        p[i].x += v[i].x * it->delta_time;
        p[i].y += v[i].y * it->delta_time;
    }
}

Both examples demonstrate a simple movement system, but flecs uses a more low-level approach with C, while Entitas leverages C# and Unity-specific features.

9,998

Gaming meets modern C++ - a fast and reliable entity component system (ECS) and much more

Pros of EnTT

  • Header-only library, easier to integrate into projects
  • Supports runtime reflection and meta-programming
  • More performant, especially for large-scale systems

Cons of EnTT

  • Steeper learning curve due to advanced C++ features
  • Less documentation and examples compared to Entitas
  • May be overkill for smaller projects or simpler use cases

Code Comparison

EnTT:

entt::registry registry;
auto entity = registry.create();
registry.emplace<Position>(entity, 0, 0);
registry.emplace<Velocity>(entity, 1, 1);

auto view = registry.view<Position, Velocity>();
for (auto [entity, pos, vel] : view.each()) {
    // Update logic here
}

Entitas:

var context = new GameContext();
var entity = context.CreateEntity();
entity.AddComponent(ComponentIndex.Position, new Position(0, 0));
entity.AddComponent(ComponentIndex.Velocity, new Velocity(1, 1));

var group = context.GetGroup(Matcher.AllOf(ComponentIndex.Position, ComponentIndex.Velocity));
foreach (var e in group.GetEntities()) {
    // Update logic here
}

Both libraries provide efficient entity-component systems, but EnTT offers more advanced features and performance at the cost of complexity, while Entitas focuses on simplicity and ease of use, particularly for Unity developers.

2,484

Specs - Parallel ECS

Pros of specs

  • Written in Rust, offering memory safety and performance benefits
  • Designed for parallel execution, potentially better for multi-threaded applications
  • More flexible and customizable, allowing for greater control over system execution

Cons of specs

  • Steeper learning curve due to Rust's complexity and specs' flexibility
  • Less opinionated, requiring more boilerplate code for basic setups
  • Smaller community and ecosystem compared to Entitas

Code Comparison

Entitas (C#):

public class MovementSystem : IExecuteSystem {
    public void Execute() {
        var entities = context.GetGroup(Matcher<GameEntity>.AllOf(GameMatcher.Position, GameMatcher.Velocity));
        foreach (var e in entities) {
            e.position.value += e.velocity.value * Time.deltaTime;
        }
    }
}

specs (Rust):

struct MovementSystem;

impl<'a> System<'a> for MovementSystem {
    type SystemData = (WriteStorage<'a, Position>, ReadStorage<'a, Velocity>);

    fn run(&mut self, (mut positions, velocities): Self::SystemData) {
        for (pos, vel) in (&mut positions, &velocities).join() {
            pos.0 += vel.0 * delta_time;
        }
    }
}

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Entitas

Entitas on Discord Latest release Twitter Follow Me Twitter Follow Me

Entitas is free, but powered by your donations

Donate

Entitas - The Entity Component System Framework for C# and Unity

Entitas is the most popular open-source Entity Component System Framework (ECS) and is specifically made for C# and Unity. Several design decisions have been made to work optimal in a garbage collected environment and to go easy on the garbage collector. Entitas comes with an optional code generator which radically reduces the amount of code you have to write and makes your code read like well written prose.

Why Entitas

Video Tutorials and Unity Unite Talks

VideoTitleResources
Video: Entitas - Shmup - Part 2Entitas ECS Unity Tutorial - Git & Unit Tests
Video: Entitas - Shmup - Part 1Entitas ECS Unity Tutorial - Setup & Basics
Video: Watch the Entitas Talk at Unite Europe 2016Unite Europe 2016: ECS architecture with Unity by exampleSlideShare: Unite Europe 2016
Video: Watch the Entitas Talk at Unite Europe 2015Unite Europe 2015: Entity system architecture with UnitySlideShare: Unite Europe 2015

First glimpse

The optional code generator lets you write code that is super fast, safe and literally screams its intent.

var entity = context.CreateEntity();
entity.AddPosition(Vector3.zero);
entity.AddVelocity(Vector3.forward);
entity.AddAsset("Player");
using static GameMatcher;

public sealed class MoveSystem : IExecuteSystem
{
    readonly IGroup<GameEntity> _group;

    public MoveSystem(GameContext context)
    {
        _group = context.GetGroup(AllOf(Position, Velocity));
    }

    public void Execute()
    {
        foreach (var e in _group.GetEntities())
            e.ReplacePosition(e.position.value + e.velocity.value);
    }
}

Overview

Entitas is fast, light and gets rid of unnecessary complexity. There are less than a handful classes you have to know to rocket start your game or application:

  • Context
  • Entity
  • Component
  • Group
Entitas ECS

+-----------------+
|     Context     |
|-----------------|
|    e       e    |      +-----------+
|       e      e--|----> |  Entity   |
|  e        e     |      |-----------|
|     e  e     e  |      | Component |
| e          e    |      |           |      +-----------+
|    e     e      |      | Component-|----> | Component |
|  e    e    e    |      |           |      |-----------|
|    e    e     e |      | Component |      |   Data    |
+-----------------+      +-----------+      +-----------+
  |
  |
  |     +-------------+  Groups:
  |     |      e      |  Subsets of entities in the context
  |     |   e     e   |  for blazing fast querying
  +---> |        +------------+
        |     e  |    |       |
        |  e     | e  |  e    |
        +--------|----+    e  |
                 |     e      |
                 |  e     e   |
                 +------------+

Read more...

Code Generator

The Code Generator generates classes and methods for you, so you can focus on getting the job done. It radically reduces the amount of code you have to write and improves readability by a huge magnitude. It makes your code less error-prone while ensuring best performance.

Read more...

Unity integration

The optional Unity module "Visual Debugging" integrates Entitas nicely into Unity and provides powerful editor extensions to inspect and debug contexts, groups, entities, components and systems.

Read more...

Entitas.Unity MenuItems
Entitas.Unity.VisualDebugging Entity Entitas.Unity.VisualDebugging Systems

Entitas deep dive

Read the wiki or checkout the example projects to see Entitas in action. These example projects illustrate how systems, groups, collectors and entities all play together seamlessly.

» Download and setup

» Video Tutorials and Unity Unite Talks

» Wiki and example projects

» Ask a question


Download and setup Entitas

GitHub releases (recommended)

Show releases

Unity package manager

Coming soon

NuGet

Entitas and all dependencies are available as NuGet packages. More detailed explanation coming soon.

Unity Asset Store (deprecated)

Entitas on the Unity Asset Store is deprecated and will not be updated anymore. The last version available on the Asset Store is 1.12.3 and is free to download. Please see discussion Entitas turns 7 - and is FREE now

Thanks to

Big shout out to @mzaks, @cloudjubei and @devboy for endless hours of discussion and helping making Entitas awesome!

Maintainers

Different language?

Entitas is available in