Entity Component System
Everything important about the ECS.
Last updated
Everything important about the ECS.
Last updated
The is part of the basic server architecture. It manages game entities, allows them to be created from compositions of different components and allows us to easily iterate over them to execute logic on them. It is the way we express and deal with game-entities. And the best... it is incredibly efficient and fast! For this, the server uses , an ECS written by the same team and one of the fastest (if not the fastest without bragging).
So where is it used and how? Well... everywhere. The whole world and the main part of the server is expressed as ECS. Already in it starts, there the world is created in which all game entities will live.
And shortly after that a , which contain the world logic and process game entities. This group is processed every few frames, it is ... it IS the game loop.
Don't worry, I left out some code in the method. Because the most important thing is the method signature. This method acts as a query. It will be executed for all game entities that match the filters of the method. The best thing to do is to browse here how exactly this works.
So the method above will be executed for all entities that:
Without a prefab component
Without a dead component
With a NetworkTransform component
With a Movement component
In this case, the method is called, passing the entity being iterated over with its requested components. And the game-time.
And if we have the entity, its transform and its movement. We can easily move the entity a little bit each time it is called. Pretty simple, isn't it?
Each of these groups is called and processed in order. Each group in turn contains several systems or further groups. Each group has a task, e.g. there is the in there, which makes sure that for entities of each frame the movement is calculated and set correctly or the which takes care of the interval saving and other entity database operations. However, groups and systems do not necessarily have to target entities.
So we have the world and the groups/systems with queries that execute logic on entities. What is still missing? Exactly, the entities themselves. They are created in many different places. For example, at the start, after the accounts are loaded, they are .
Or when creating new areas and chunks in the world.
Let's take a quick look at the within the to see what such a system and a query looks like.