Hytale Modding
Hytale Modding

Entity Component System

Uma introdução básica ao ECS (Entity Component System)

Aviso

This guide requires basic understanding of OOP concepts such as inheritance.

Please make sure you have a good understanding of these concepts before reading this guide.

Informação

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 inherit a class in Java, we inherit all of its attributes and methods. While in composition we can choose for each object what it references and what systems will work on it.

Entidades, componentes e sistemas

Entidades

Uma entidade é apenas um identificador único.

  • It contains no data.
  • It contains no logic

Think of entities as nouns that can be described using components

Componentes

Components are just plain data containers.

  • Eles armazenam apenas dados;
  • Eles não contêm comportamento nem lógica;
  • Eles descrevem características ou aspectos de uma entidade.

Exemplos de componentes:

  • Um componente "position" que armazena coordenadas X, Y e Z;
  • Um componente "velocity" que armazena a velocidade ao longo de cada eixo;
  • Um componente "health" que armazena a vida atual da entidade.

Think of components as adjectives that describe an entity

Sistemas

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

Por exemplo:

  • 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.