liveBook · Manning

Component

As explained in High Performance Unity Game Development

An ECS data unit that stores an attribute or group of attributes associated with an entity.

In an ECS design, a component is an array of data, an entity is an index into that data, and a system is the logic that modifies it. For enemy movement, EnemyPosition is the component array; each enemy’s position is accessed by its index. section 12.3 section 12.5

Components help organize entity data in a cache-friendly layout, but ECS can require separate components for each piece of data and systems for each calculation. Directly storing gameplay data in arrays and operating on it may provide data-oriented benefits with less code. section 12.3 section 12.5

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 enemy movement loop uses the entity index to read and update each position in the component array. section 12.3

How High Performance Unity Game Development covers it

How deep it goes
Maps components to arrays and entities to indices, then discusses ECS overhead without detailing component schemas.
Examples
Uses EnemyPosition as an array component in an enemy movement loop.
What you can do after
Understand how ECS maps component data to arrays and assess whether its extra code is warranted.
How it connects
Connects components to entities, systems, data-oriented design, and cache-friendly storage.

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.