Entity Component System
A basic introduction into ECS (Entity Component System)
This guide requires basic understanding of OOP concepts such as inheritance.
Please make sure you have a good understading of these concepts before reading this guide.
This guide is currently only on the theory of ECS and will not have code examples.
Code examples are intentionally omitted to avoid confusion about how Hytale’s ECS may be implemented.
Introduction
An Entity Component System otherwise known as ECS is a design pattern in game development.
ECS is made up of Entities, which reference Components and Systems that operates on Entities.
It also focuses on composition over inheritance, eliminating rigid hierarchy, helps separate behavior and data and makes reusability easier.
Composition Over Inheritance
Before getting into understanding what ECS is made of, lets understand what is the ECS philosophy.
We can describe composition as "has X" and inheritance as "is X". When we inherite a class in Java, we inherite all of its attribues and methods. While in composotion we can choose for each object what it refrence and what systems will work on it.
Entities, Components and Systems
Entities
An Entity is just a unique identifier.
- It contains no data.
- It contains no logic
Think of entities as nouns that can be described using components
Components
Components are just plain data containers.
- They store only data
- They contain no behavior or logic
- They describe traits or aspects of an entity
Examples of components:
- A 'Position' component that stores X, Y and Z coordinates
- A 'Velocity' component that stores the speed along the each axis
- A 'Health' component that stores the current health of the entity
Think of components as adjectives that describe an entity
Systems
Systems contains the logic for your game (or in this case, a mod).
- It Operates on all entities that have a specific set of components
- It Does not store entity data itself
- It Applies behavior by reading and modifying component data
For example:
- A "WinConditionSystem" may process every Entity that contains the components "Position" and "Velocity"
- If an entity reaches the position
(0, 0, 0), the system will trigger a "You Won!" message.