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
