← Back to Roadmap
Composition over inheritance - build entities from components
Data-oriented - components are just data
System processes entities - logic lives in systems, not components
Query-based - systems query for entities with specific components
ECS Fundamentals
15 minLearn the Entity Component System architecture that powers Hytale.
What is ECS?
Entity Component System (ECS) is a design pattern that separates data from logic:
- Entity: Just an ID - a unique identifier for a game object
- Component: Pure data - health, position, velocity, etc.
- System: Pure logic - processes entities with specific components
Why ECS?
Traditional OOP uses inheritance hierarchies. ECS uses composition:
java
// OOP approach - rigid hierarchy
class FlyingEnemy extends Enemy { }
class SwimmingEnemy extends Enemy { }
class FlyingSwimmingEnemy extends ??? // Problem!// ECS approach - flexible composition
entity.addComponent(Flying.class);
entity.addComponent(Swimming.class);
// Done! No inheritance issues
Hytale ECS
In Hytale, you work with:
Holder- an entity referenceComponenttypes - data containersEntityTickingSystem- your logic
java
// Get a component from an entity
Player player = holder.getComponent(Player.getComponentType());// Check if entity has a component
if (holder.hasComponent(Health.getComponentType())) {
Health health = holder.getComponent(Health.getComponentType());
}