ECS

Definition

@sander-mertens

Entities & Components

  • An entity is a unique identifier
  • A component can optionally be associated with a plain old datatype
  • A component identifier is an entity
  • An entity can have 0 .. N components
  • A component can be annotated with a role
  • An <entity, component> tuple can have 0 .. N components

Systems

  • A system is logic matched with entities based on their components
  • A system is invoked as result of an event
  • A component mutation is an event
  • Computing a simulation frame is an event
  • A frame is divided into N phases
  • Each system is assigned to a phase

https://forums.coregames.com/t/advanced-code-architecture-for-core-part-2-entity-component-system/3194

  • ECS game object is a DDD Entity; an ECS Entity is a DDD Identity; an ECS Component is a DDD Domain Model; and an ECS System is a DDD Service or Aggregate Root.
    • Thoughts i.e., an "ECS game object" is the entity (which is just an ID + list of components) + the functionality and data given by components?

Implementations

other implementations

Wish List

Entity Relations

Issues

  • https://medium.com/@rdolivo/ecs-for-gamedev-with-typescript-5a1204f594bc
    • Systems are highly dependent on the order in which they are added because their logic works out consistently. Adding new systems between existing ones can be a difficult task.
    • Changing the content of components can potentially break down many systems.
  • "Anything that needs a dynamic ordering of execution is not very intuitive in ECS"
    • https://forum.unity.com/threads/why-vanilla-ecs-is-not-enough
      • "Why not put the 'timer' in each component ? Yes you'll need to have one system to update the timer of each type of component having a time... it would be better to have a timmer logic that store the next tick time instead of storing aremaining time that you update every frame. It would allow to make use of the DidChange filtering. Also you could probably define a ITimer interface that your ComponentData would implement and taht should allow you to stream line the timer update systems a bit through generics."
  • "One of the biggest "obstacles" (questions) I see is that there will always inevitably be the need to interface with long-running "continuous" processes (maybe because of networking with a much different frequency than the one ECS pipeline of systems is being executed with, maybe because devs will want to use an already written external library spawing own threads without any poll-like API, maybe because there will be a separate event loop system which will not easily integrate with the ECS event loop, etc.)."
  • Spatial Storage
    • "How to store spatial data in ECS?

Spatial data structures like quadtrees and octrees are usually not directly stored in an ECS, as their layout does not match well with the typical ECS layout.

One approach that works well for narrow-phase spatial queries in combination with an ECS is to create a query that iterates relevant entities and stores them in a spatial structure at the beginning (or end) of each frame.

For broad-phase spatial queries an application could leverage runtime tags (if the ECS supports it) where a tag corresponds with a cell in a spatial grid. Combined with queries that match the tag, an application can quickly discard large groups of entities that are not in a certain area."

Scripting

  • https://www.reddit.com/r/gameenginedevs/comments/13dd4k9/scripts_in_ecs/ has two suggestions, moved toward #2:
    • "create a special script component and then a system to process these script components."
    • "store a reference to the script (function pointer in the example, but could be a function name or id if the script is something like Lua) in components and then have that components system call the script."
      • scripts get queued and my scripting engine is decoupled from the ECS.

Resources

List


Backlinks