When not to use ECS (Entity Component System)?

Author profile picture

@icex33Maxim Zaks

I just watch an excellent talk by Kirill Nadezhdin about ECS for game development. The talk is in Russian, it should get english subtitles in the future though.

In the Q&A session, there was a question about when not to use ECS. This question comes up pretty often and ECS advocates (me included) always have tough time to reply, as we like the paradigm and it is really hard to find flaws in things you like. However the question also comes from a “wrong” angle. ECS is perceived as a library, however in reality it is more about way of thinking. So the question is rather, when should I not think this way… And the answer is:

“Don’t think this way, when this way of thinking does not provide you more/any benefit”.

Next question arise:

“How do I know, when this way of thinking does not provide benefit?”

And the answer to that is:

“Well, you need to think about, or try it” 😜

I tried and though about ECS for over 5 years now. Here are my thoughts:

There are two types of computing:

  • Pure computing, we receive input and produce output, the application has single purpose and it’s life cycle is bounded to computation itself
  • Interactive computing, where a system runs over time and receives input

Examples of pure computing are — compilers, bash scripts and generally functions.

Examples of interactive computings are — apps, games and simulations.

In my opinion, when you need to write a pure computing software ECS can’t help you much. Main mantra of ECS is separation of state and behaviour. When we have pure computing, we should pass the state along concatenated functions. So in my opinion, paradigms from functional programming are the most sane way of thinking here.

When we do interactive computing, we have state accumulated over time and we are dependent on external input. In this situation, ECS is helpful. For me thinking about data first, helps building decoupled scalable and simple logic on top. And in my opinion this is the most important qualities from perspective of app / game / simulation developer.

However there are also other perspectives, you might be caught in position of infrastructure development. Meaning — your job is it to provide building blocks for other people to use. Your building blocks has to have well defined interface and have to be stable. You need to build something that is easy to use, providing an illusion of simplicity. This is what I call complex made easy. As a “middle man” you need to be able to provide something like this, other wise there is no need in you. If you are caught in such position, than paradigms from object oriented programming are what will bring you the most benefit.

So in conclusion.

Use FP when you need to build something purely computational.

Use OOP when you want/need to build something generic for other people to use.

But if you are application or game developer, ECS way of thinking brings a lot of benefit to the table.



The Noonification banner

Subscribe to get your daily round-up of top tech stories!