liveBook · Manning

Entity component system

As explained in High Performance Unity Game Development

ECS is an architecture that represents entities separately from their data components and the systems that process those components.

Suppose a survival game must move many enemies toward the center of its board. An entity component system (ECS) organizes this work by separating entity identities, gameplay data, and the logic that processes that data. It is a way to implement data-oriented design, not a prerequisite for it. section 1.5 section 12.3

In a simple array-based enemy-movement example, the three parts correspond to:

  • Entity: the index identifying which enemy’s data to access. section 12.3
  • Component: the array holding enemy positions. section 12.3
  • System: the calculation that updates those positions. section 12.3
Listing 12.10 Original enemy movement before DOTS
static void moveEnemies(GameData gameData, Balance balance, float dt)
{
    for (int i = 0; i < balance.NumEnemies; i++)
    {
        Vector2 dir = -gameData.EnemyPosition[i].normalized;
        gameData.EnemyPosition[i] = gameData.EnemyPosition[i] + 
                                    dir * balance.EnemyVelocity * dt;
    }
}

The loop demonstrates the array-based analogy, not an ECS implementation: each index selects a position, and one static function updates the positions. Keeping the data together supports cache-friendly access without requiring an ECS conversion. section 12.3 section 12.5

Unity ECS formalizes cache-friendly entity-data storage, but adopting it means creating components for data and systems for calculations. It also works with entities rather than GameObjects, so converting an existing GameObject-based game adds work. Start with the performance problem: arrays and static logic may already provide the needed data locality. Burst, Jobs, and TransformAccessArray are separate Unity DOTS options that can be added selectively; none makes ECS mandatory. section 12.3 section 1.5

How High Performance Unity Game Development covers it

How deep it goes
Defines entities, components, and systems through an enemy-movement array loop, but stops short of implementing a full ECS conversion.
Examples
Uses an indexed enemy-position loop and a Unity physics integration diagram to contrast ECS with array-based gameplay logic.
What it assumes
Assumes familiarity with Unity GameObjects and array-based gameplay logic while defining the three ECS terms through a simple loop.
What you can do after
Evaluate/understand it by weighing cache-friendly storage against component, system, and GameObject-conversion overhead in a Unity game.
How it connects
Relates ECS to data-oriented design, Unity DOTS, GameObjects, Burst, Jobs, and TransformAccessArray.

Also explained in

Compare how 2 books explain entity component system →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of High Performance Unity Game Development. The section links point to the parts of the book it draws on.