Skip to main content
OverflowAI is here! AI power for your Stack Overflow for Teams knowledge community. Learn more
14 votes

I don't get why ECS is considered more performant than OOP

With an OOP architecture, you usually end up with code which if unrolled to a purely procedural style would look like this: ...
Philipp's user avatar
  • 120k
13 votes

What is a pure ECS?

A pure Entity - Component - System architecture means that: Every object in your game is an Entity. However, an entity itself has neither any data nor any code. It is an abstract concept not ...
Philipp's user avatar
  • 120k
11 votes
Accepted

How could I implement an ECS in C?

As a pattern ECS and data oriented programming in general are closer to pure C than C++. Entity component systems consist of three major elements. Components are simply holding data; they shouldn't ...
Exaila's user avatar
  • 687
10 votes
Accepted

In Bevy ECS, what is a good way to have entities reference each other?

You shouldn't have to "loop through" all instances of a query. Query lookups are typically implemented in such a way that they are fast -- often constant or logarithmic time complexity. Bevy ...
Joshua Hyatt's user avatar
9 votes
Accepted

What should be an entity/component, and what shouldn't?

A lot of systems in a game that needs to be updated are things that are not rendered and don't need any input, they simply need a call to their update function every frame. They don't have any ...
DMGregory's user avatar
  • 135k
8 votes
Accepted

Unity Hybrid ECS with "old way"

It is perfectly possible to mix both styles. The same GameObject can have some of its functionality implemented with the new ECS system and other functionality in classic MonoBehaviour events. What ...
Philipp's user avatar
  • 120k
8 votes
Accepted

Dealing with more complex entities in an ECS architecture

Games typically approach this type of issue using a transformation hierarchy. In this model, each entity can be treated as a "child" of a "parent" entity. The entity's local ...
DMGregory's user avatar
  • 135k
8 votes
Accepted

Who 'owns' the components in an ECS?

In an actual ECS, entities are just IDs, they don't own the components. Components are usually registered into a container that represents the scene/world the game is currently in. The reason is ...
starikcetin's user avatar
  • 5,275
7 votes
Accepted

Is an ECS viable in garbage collected languages?

The Garbage Collector (GC) is not really an obstacle to implement an Entity-Component-System (ECS) architecture. All you need is a root object for your ECS. It would hold references to the containers ...
Theraot's user avatar
  • 26.9k
7 votes
Accepted

In ECS, how to decrease health?

You're on the right track: systems are where the logic resides and where behaviors are implemented. Systems are basically functions where the arguments are components. So if you wanted to create a ...
Mattia's user avatar
  • 398
6 votes

Should components in Entity Component System pattern have logic?

I was considering voting to close this question as opinion-based, but I think there are a couple of misunderstandings about Entity-Component Systems and Data-Oriented Design here that are worth ...
DMGregory's user avatar
  • 135k
6 votes
Accepted

Is it a good idea to use a hash table in an ECS?

If you want to know what is faster, measure. That is the engineering approach. Thus, write your code in a way that you can swap the implementation (e.g. behind an interface) and benchmark. With a ...
Theraot's user avatar
  • 26.9k
5 votes

Fastest way to look up an entity with a set of components?

The way ECS implementations like the new one in Unity work is to use the concept of Archetypes. An Archetype is the description of the components in a particular entity. Given sets of components, ...
Sean Middleditch's user avatar
5 votes
Accepted

Handling input in a custom ECS engine

I think you're pretty close. Here is one option, which I'd try to implement first. You need 2 components Input Camera I ...
Vaillancourt's user avatar
  • 16.3k
5 votes
Accepted

How to implement n-body in an Entity Component System

One nice thing about systems in an ECS architecture is that they don't all necessarily need to follow the same structure of ...
Philipp's user avatar
  • 120k
5 votes

What is a pure ECS?

Here's an article explaining it quite clearly: https://www.gamedev.net/articles/programming/general-and-gameplay-programming/understanding-component-entity-systems-r3013/. A component can be likened ...
Ilmo Euro's user avatar
  • 176
5 votes

In C#, is there any performance reason to implement ECS?

Performance will always depend on implementation. It's definitely possible to make well-performing non-ECS games, or poorly-performing ECS games, but there are certain performance tricks that ECS ...
DMGregory's user avatar
  • 135k
4 votes
Accepted

Entity Component System: where do I put containers?

Update I have wrote Theraot.ECS inspired by Fastest way to look up an entity with a set of components?. However this answer motivated me to allow to specify custom containers for particular types. ...
Theraot's user avatar
  • 26.9k
4 votes

Entity Component System: where do I put containers?

Just like with any software architecture question, the short answer is "It depends..." Where do I put that quadtree? Any auxiliary data structures needed by one system only should be part of that ...
Philipp's user avatar
  • 120k
4 votes
Accepted

How does ECS handle systems which need to know more about the environment of the entities it processes?

My solution to this would be to create a component AITarget which marks an entity as something zombies are supposed to attack (like a player or a civilian). Now ...
Philipp's user avatar
  • 120k
4 votes

Is it a good idea to use a hash table in an ECS?

I'd agree with Panda Pajama's advice: How about you start with what you think makes the most sense, and build from there? Optimizing too early for a very specific use case may end up backfiring -- at ...
DMGregory's user avatar
  • 135k
4 votes
Accepted

Unity DOTS/ECS: Spawning entity programmatically at specific location

After you instantiate the entity, try: ...
Charly's user avatar
  • 742
4 votes

ECS - Components that access other components

Position doesn't have any behaviour, it's just accessed by a bunch of things. Should it even be a component? Just data without behavior is pretty much the definition of a component in ECS. I have ...
Philipp's user avatar
  • 120k
3 votes
Accepted

Unity conversion of Gameobjects to ECS

Its look like that you have not installed the "Hybrid Renderer" Package. When you want to convert Game objects to Entities then you have to also install "Hybrid Renderer" from package manager. ...
Swati's user avatar
  • 1,147
3 votes

How do I build the dependency graph on ECS?

Make a Immovable component that contains a set※1. The idea is that when this set is empty the entity can move. We can do this by having The ...
Theraot's user avatar
  • 26.9k
3 votes
Accepted

Should fields in components in an ECS use polymorphism?

feels like I'm violating the ECS rule There is no ECS police that will come and put you in ECS Jail. This is your architecture, you set it up how it fits your needs. having any functionality in ...
Vaillancourt's user avatar
  • 16.3k
3 votes

How can I handle scripting-like tasks in my ECS?

I'd recommend solving this in pretty much the usual way: with a scripting language. (This could be a text-based language like LUA, a nodegraph based visual scripting tool, pre-digested bytecode, etc.) ...
DMGregory's user avatar
  • 135k
3 votes

How to Implement ECS Archetypes in C#?

Here is a sketch of how you can implement an archetype in C#: ...
DMGregory's user avatar
  • 135k
3 votes

Question on parallelizing ECS Systems

Pipelines The simplest implementation of ECS will run systems sequentially one after the other. Perhaps you are familiar with the idea of fixing your timestep. Simply running systems sequentially in a ...
Theraot's user avatar
  • 26.9k

Only top scored, non community-wiki answers of a minimum length are eligible