10

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?

CosmicGiant
  • 6,275
  • 5
  • 43
  • 58
  • 2
    "Composition over Inheritance" comes to mind – Draco18s no longer trusts SE Oct 28 '19 at 19:12
  • 2
    Moving to ecs coding is a little like the brain farts many of us went through to go from linear to oo. While how to use ecs is still changing and unity continue to try working it, while the core principle doesn’t change some of how does and its a bit chasing a moving goal post if you dont have the time to invest. I think it will be a must for wome of yhe more cinematic stuff like say the battle of 5 armies style work, but for random platformer or time waster games unlikely, rpg styles..... maybe but only maybe – BugFinder Dec 23 '19 at 02:18

2 Answers2

10

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.

Sam
  • 794
  • 1
  • 7
  • 26
  • 1
    On the first point, sin't that already the case with both OOP and normal EC ("Standard Unity")? Generally, you already have to make components and systems self-sufficient enough not to depend on execution order of other stuff, or abstract enough that order doesn't matter in the first place(?), so I'm failing to see this as a disadvantage of ECS specifically, and rather as general problem in programming. --- Point #2 is kinda the same. Isn't that a general problem in structuring data(?) – CosmicGiant Apr 19 '20 at 04:48
  • #1 was mostly to point out that no, you don’t remove all dependency problems with ECS, you still have dependency on the systems execution order. For #2, since you should encapsulate your data in OOP, I would tend to say the problem isn’t as big? Encapsulation doesn’t really exists in ECS (and shouldn’t) – Sam Apr 19 '20 at 14:54
2

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.

travelhawk
  • 134
  • 6