Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the disadvantages of the ECS (Entity-Component-System) architectural pattern, compared to OOP (or other paradigms)?

Because of Unity ECS, I've been reading a lot about ECS lately.

There are many obvious advantages to an ECS architecture:

ECS is data-oriented: Data tends to be stored linearly, which is the most optimal way for the system to access it. In decent ECS implementations, data is stored and processed sequentially, with few or no interruptions for any given system processing it's set of components.

ECS is very compartmentalized: It naturally separates data from behavior, enforces 'composition over inheritance' (google it), etc.

ECS is very friendly to parallel-processing and multi-threading: Because of the way things are structured, many entities and components can avoid conflicts and be processed in parallel to other systems.


However, disadvantages to ECS (compared to OOP, or Entity-Component [without systems], as is common in game-engines including Unity up until recently) are rarely, if ever, talked about. Do they exist? And if they do, what are they?

like image 468
XenoRo Avatar asked Oct 28 '19 19:10

XenoRo


People also ask

What is ECS architecture?

Entity Component System (ECS) is a software architectural pattern mostly used in video game development for the representation of game world objects. An ECS comprises entities composed from components of data, with systems which operate on entities' components.

Is ECS an OOP?

The fact that ECS can be implemented in OOP languages doesn't make it an OOP pattern, only that OOP languages have Turing-completeness. You could also write Pure-FP code or implement Prolog in an OOP language, or vice-versa. > If you move the global functions to the entity objects themselves, you end up with OOP.

What is ECS entity component system unity?

The Entity Component System (ECS) is the core of the Unity Data-Oriented Tech Stack. As the name indicates, ECS has three principal parts: Entities — the entities, or things, that populate your game or program. Components — the data associated with your entities, but organized by the data itself rather than by entity.


2 Answers

Here's a few points I gathered from my research:

  • Systems are very dependent on their ordering. Introducing new systems in between already existing Systems can be a challenge.

  • You also need to plan ahead your data as much as possible, since they will potentially be used by a LOT of systems. Changing the content of components could potentially break quite a few systems.

  • Although it's easy to debug the flow of a system, it's also harder to debug single component changes and not have a global view of what happened to the entity across all it's components. I'm not sure if Unity introduced new debug features for this.

  • If you're planning to use ECS in your team, introducing a new paradigm to devs that are not familiar with it could be a challenge. The onboarding time could be longer with more overhead.

Hope this gives you a good starting point.

like image 108
Sam Avatar answered Sep 29 '22 14:09

Sam


When it comes to Unity3D, one disadvantage which comes to my mind is that the ECS there is quite restricted to the Unity classes (e.g. MonoBehaviour) and lifecycle. That means that the components are not easy to share with other C# code whereas a well-designed OOP class is reusable by other platforms than Unity.

Another point which comes to my mind is that using Interfaces with Components is sometimes not easy in Unity because only in the newest version serialization of interfaces are supported. Without serialization there don't appear inside of the inspector.

like image 28
travelhawk Avatar answered Sep 29 '22 15:09

travelhawk