ECS gives me migraines.
At first it sounds like a great idea, but you soon end up in a situation were a tiny change in the game can have a massive effect on performance.
Well, the performance hit can happen in any other architecture, too.
It really depends on your definition of an "Entity".
Consider the full on approach where you have an entity that for everything and game objects are bags of entities. So a character running around the game would have ...
SkinnedMeshEntity, WeaponEntity, HealthEntity, BackpackEntity, etc. Each of those would have it's own bag of entities. (TransformEntity, CollisionBoxEntity, ......)
ECS stands for Entity Component System, although IMHO "component based entity system" would be better. A "game object" is often used as a synonym for entity.
With this in mind ...
* SkinnedMesh is a component,
* Weapon is probably an entity by its own rights (because it should probably be exchangeable),
* Health is a component, or perhaps better a variable of a Constitution component,
* Backpack is perhaps an entity with an Inventory component (if used as an item by its own), or perhaps only an Inventory component.
Other things like e.g. terrain are (should be, at least ;)) never an entity, so "the full approach" is wrong from the start. However, what's wrong with a weapon, a clip of ammo, or a health pack (not the Health constitution!) being own entities? What's wrong with each of them having its own placement, its own mesh, and other components? Nothing, because your game needs this! You want the weapon to lie around on the ground, ready to be picked up. So it is placed in the world. The weapon has its own mesh clearly.
So suddenly this one game object contains hundreds of entities. Nasty but workable. Things get really nasty when you start needing references between entities.
Well, I think dozens of components would already be more than sufficient. However, the aspect you are indicating here, if I understand you correctly, is that parts that were usually embedded as simple variables, now become their own software objects. The typical example is the placement, since close to everything is placed somewhere in the game world and hence needs a placement. Point is that "close to everything" is not "everything", and with a reasonable amount of static geometry it may be even wrong at all as an argument. However, even if I accept that a placement is needed by close to everything, it is just a single isolated example in front of a much greater couple of counter examples. And of course you are not hindered in the end to embed some "very important components". E.g. Unity3D does so with the placement, too, although I do not agree with this approach ;)
The weapon needs bullets, so it has a reference to a BulletMagazineEntity. A skinned mesh needs an animation entity. A character needs a target to shoot at, which is an entity.... you see were this is going?
Again, use the solution that is suitable.
* A firearm weapon needs ammo, it does not need a BulletMagazine per se. After picking up a ammo clip, the ammo counter could simply be increased and the clip entity could be wasted.
* There is no technical / architectural reason why a skinned mesh (a component) needs an animation (a component). It is a decision of the designer. S/he could create a static skinned mesh entity. Also, it's the entity that needs both the skinned mesh and the animation (as said, by design).
* A character needs a target to shoot at, which is an entity ... well, what should it be otherwise? I go even further: I say that shooting is an action that checks against a BoundingVolume component of an entity, and if the hit test passes, it causes a defined decrement of a variable called "Health", to be found in the Constitution component of the targeted entity. There is no Constitution / Health? Then shooting to death is not possible. There is no CollisionVolume? Then aiming at the entity is not meaningful, perhaps not even possible. (One can see from this example, that components can be used also to tag entities for game related purposes. You can even mark a BoundingVolume to be used especially for shooting, for example.)
It gets even worse if you have multiple entites with a reference to the same entity. Null pointers can really ruin your day.
This happens regardless of the architecture, because it is a much more lower level problem. Even an unresolvable relation in a game item database has this effect.
Well, the thing is that the representation of problems comes from the game design. The software architecture should be powerful enough to solve the problems, and this not only acutely but also in the long term
As with everything, the programmer can make mistakes, regardless of whether ECS or not is in use. As with everything, also ECS is not the silver bullet. But for a common problem in game development, it is a better approach than others are. As said, this doesn't mean that every occurring problem should be mangled into the ECS; there are parts that do not fit.
Just my 2 Cents. Perhaps also a bit biased ;)
EDIT: Oh, forgotten to say: It is true that properly implementing an ECS is its own can of worms. There are many aspects to consider, many routines to go, and going the wrong route will have negative impacts like performance lost. It implies a great hurdle. But that doesn't mean that the architecture is bad in itself. Instead it means that there are good and bad approaches.
Edited by haegarr, Today, 02:50 AM.