skip to content

When should a team adopt an ECS in an existing game built on inheritance-based objects, and how would you migrate it incrementally?

level: principalimportance: should knowfreq 35%

answer

  1. profile before choosing a model
  2. many similar objects, hot loops
  3. an ECS island beside the objects
  4. one owner per piece of state
  5. tools and scripting expect objects

basics

~20 s

Adopt an ECS where profiling shows hot loops over many similar objects stalling on memory. In a shipped game, start with one hot subsystem as an ECS island, bridged to the object model by ids, and expand only on measured wins.

solid answer

~50 s

I'd start from measurements, not from the pattern: an ECS pays off when frame time is spent iterating thousands of similar entities, such as a swarm, projectiles or crowds, and captures show those loops stalling on cache misses. It does little when the cost is in a few hundred unique scripted objects. The rest of the decision is cost: editor tools, save games, the scripting layer and debug views all assume the object model, and the team must learn to think in data and systems. For a shipped codebase I'd rarely rewrite. I'd pick one hot subsystem, move its data into an ECS island, link each legacy object to its entity by id, give every piece of state one owning side and copy across once per frame at a defined point. I'd expand only when the measured gain outweighs maintaining two object models, and agree up front what would make us stop.

go deeper

for a junior

Recall that an ECS pays off for many similar objects processed every frame, and that a shipped game rarely switches models all at once.

for a middle

Explain why a hybrid needs a bridge between objects and entities, and why references across it should be ids rather than pointers.

for a senior

Plan the first migrated subsystem: the baseline, the ownership of each piece of state, the per-frame sync point and the command-buffer rule.

for a principal

Weigh the three options against profile evidence, tools, scripting, schedule and team cost, and commit to a stop condition before the first line moves.

## What the decision actually is Whether to use an ECS is rarely a yes-or-no question for a game that has already shipped. The realistic options are: | Option | What it means | When it fits | |---|---|---| | Keep the object model, fix hot spots | Rewrite one or two hot loops over plain structure-of-arrays data, with no general ECS | A handful of hot loops, a small team, a short horizon | | Hybrid ECS island | Move one hot simulation into an ECS, bridged to the existing objects | Several hot, homogeneous simulations and a longer horizon | | Full migration | Rebuild the object model on an ECS | A new engine generation, with tools being rebuilt anyway | A lead's job is to pick among these with evidence, and to know what each one costs the team for years. ## Signals that favour adopting an ECS - **The profile says so.** Frame time is spent iterating thousands of similar objects (a swarm, projectiles, crowds, debris), and captures show those loops stalling on cache misses rather than on arithmetic or waiting for the GPU. - **Entity counts are a design goal.** The game needs many times more simulated units than the object model can afford. - **Composition pain.** Designers want combinations of behaviour that the class hierarchy cannot express without new classes. - **The data is homogeneous.** Many entities share the same few components and the same update. ## Signals against - **The cost is somewhere else.** If frame time goes to script calls, rendering, or a few hundred unique scripted objects, an ECS will not move the number. - **Tools assume objects.** The editor, save games, the scripting layer and debug views are built around object references and class types; each needs a bridge or a rewrite. - **Team cost.** Thinking in data and systems takes time to learn, and two object models in one codebase must both be maintained. - **Schedule.** A model change late in a project risks bugs everywhere for a gain in a few places. ## An incremental migration plan If the evidence supports it, a hybrid is usually the safe first move: 1. **Measure and pick one subsystem** whose cost is dominated by iterating many similar objects, and record a baseline frame time for it. 2. **Define its components as plain data** and write its systems over queries. Keep the authoring format the tools already write, and convert at load time. 3. **Bridge by id.** Each legacy object that has a counterpart stores its entity id, and the ECS side stores the object's handle if it must call back. Neither side keeps raw pointers into the other's storage. 4. **Give each piece of state one owner.** If the ECS owns positions, the legacy side only reads them; copy across the boundary once per frame at a defined point, in one direction where possible. 5. **Route structural changes through command buffers** from day one, so code on either side cannot disturb storage mid-iteration. 6. **Compare against the baseline.** Move to the next subsystem only if the gain is real and the bridge cost stays small. ## Rules a lead sets - Which subsystems are ECS-owned, written down, so state does not drift into both models. - How entities are referenced across the boundary, and that every lookup checks the id is still valid. - Who may add component types and how they are named and documented, so components stay small and plain. - How the debugger, the editor and the profiler show ECS data, so the new model is not a black box. ## How to know it worked - The migrated subsystem's frame time dropped by an amount that matters against the frame budget, and stayed down as entity counts grew. - The bridge's own cost, copying and id lookups, is measured and small next to the gain. - Designers can build new combinations as data, and bugs at the boundary are falling, not rising. - There is a stop condition: if a migrated subsystem does not beat its baseline, the team keeps the object model there and says so. There is no single right answer. A small team shipping a game with a few hundred objects is often best served by a couple of hand-written structure-of-arrays loops, while an engine team planning for years and many times more entities may justify a full migration. What interviewers listen for is that the choice is driven by measurements and by the long-term cost to the team, not by the pattern's reputation.

  • What goes wrong most often in a hybrid codebase with both game objects and an ECS?
    The bridge. If state is copied both ways several times a frame, the sync cost eats the gain and bugs appear when one side reads stale data. Keep ownership clear, so each piece of state has one authoritative side, copy at one defined point per frame, and refer across the boundary by id with a validity check, never by pointer into component storage.
  • When would you choose a full migration over a hybrid?
    Rarely for a shipped game. It fits a new engine generation or a sequel with a rewrite budget, where most frame time is in homogeneous simulation and the tools are being rebuilt anyway. Even then, migrate in vertical slices that each stay shippable, with a baseline for every slice.

  • An ECS is the modern way, so the whole codebase should be rewritten to one.
  • Adopting an ECS will improve performance without profiling first.
  • The bridge between objects and entities costs nothing because it only copies.
  • Tools, save games and scripting are unaffected by a change of object model.
  • A few hundred unique scripted objects benefit from an ECS as much as a swarm does.