Skip to content

Svelto.ECS concepts

alex hall edited this page Mar 22, 2020 · 31 revisions

Note: this page alone won't be sufficient to explain the basic concepts, you must read also the articles at the end of the page (from the oldest to the newest)

Entity:

The concept of Entity is abstracted in ECS paradigm, meaning an Entity object doens't actually exist. While this is true in Svelto too, conceptually it must be seen as a real entity that can be explained in game design terms. The name of each entity should reflect a specific concept from the game design domain. The risk of using abstract entities is to see entities just as a data container which would lead to use ECS just as a mere procedural + global accessible data paradigm which would lead to spaghetti code all over again.

IEntitiesDB

if you see entities as just IDs to a collection of data structures that belong to that entity, the ID can be seen as a primary key of a database, while the data as a record in a table defined by the entity template.

EntityDescriptors:

in Svelto ECS the entity template is the EntityDescriptor. It gives a way to formalise your Entity, it also defines the EntityStructs and EntityViewStructs that must be generated once the Entity is built

EGID

the EGID is the ID of your entity. The concept of EGID in Svelto is a bit more complicated than that. It is formed by the actual entity ID and the group ID of the group the entity belongs to. the ID part is constant, but the groupID can change if the entity moves between groups.

Engines (Systems):

Where all the logic lies. Engines operates on EntityViewStructs and EntityStructs. Engine can query entity views through the entitiesDB. Read more about it here: https://github.com/sebas77/Svelto.ECS/wiki/How-to-design-an-Engine

EntityStructs (Pure Data Components):

EntityStructs is the preferred way to store the entity data. They are just plain structs of pure data (no objects). The promote data modularity and they should be very abstracted. Entities become specialized through the composition of this data, because more entity structs an entity generate, more engines will consequentially apply behavior on them.

Put another way: EntityStructs are Svelto.ECS's version of a pure data Component. Some find it easier to think of them as Components.

EntityViewStructs (Hybrid Components):

EntityViewStructs are used to wrap Objects that come from OOP libraries. You shouldn't use them unless you need to mix your ECS code with OOP code of external libraries or underlying platforms (including Unity itself). The OOP Objects are known to Svelto through Component Interfaces. Because of the object nature, EntityViewStruct components data can be reinterpret (the same implementor can implement several component interfaces) so that an EntityViewStruct can be designed around engines. This must be done cautiously, as modular EntityViewStructs are still prefer over "fat" entity view structs

Put another way: EntityViewStructs are Svelto.ECS's version of a hybrid component component composed of interfaces and data. Some find it easier to think of them as HybridComponents.

Component Interfaces:

Components Interfaces must be seen as data holders. In Svelto.ECS EntityViewStructs hold Component Interfaces and these interfaces always declare Setters and Getters of Value Types coming from the Objects they wrap

Implementors:

The components interfaces must be implemented through Implementors and the implementors are the Objects you need to wrap. In Unity Implementors are always Monobehaviours.

ExclusiveGroups:

Entities are stored in groups. Groups in SECS are of fundamental importance. They do not just split entities in different containers, they represent the state of the entity itself and should be seen as such. When the code reach a given complexity, ExclusiveGroups must be fully understood. For this reason read:

https://github.com/sebas77/Svelto.ECS/wiki/Svelto.ECS-ExclusiveGroups https://github.com/sebas77/Svelto.ECS/wiki/Svelto.ECS-memory-layout

Svelto ECS 2.8 update:

http://www.sebaslab.com/introducing-svelto-ecs-2-8/

Svelto ECS 2.7 update:

http://www.sebaslab.com/svelto-2-7-whats-new-and-best-practices/

Svelto ECS 2.5 update:

http://www.sebaslab.com/svelto-ecs-2-5-and-allocation-0-code/

Svelto ECS 2.0:

http://www.sebaslab.com/learning-svelto-ecs-by-example-the-unity-survival-example/ http://www.sebaslab.com/svelto-ecs-2-0-production-ready/

Clone this wiki locally