m05 · Baking · drill · 45 min
Bake a spawner that survives a scene reload
Why this is a drill and not a lab
The labs in this course hand you a host file, numbered steps, and the code to paste. That format proves a mechanism behaves as claimed, and it is the right format for measurement.
It is the wrong format for this. Every piece of knowledge you need is in the
five readings behind you — bakers and tracked reads, entity scenes and
remapping, prefabs and the Prefab tag,
So there is no host file. There is a goal, a set of constraints, and a set of checks you run yourself. The constraints are not arbitrary difficulty — each one closes off the shortcut that would let you finish without doing the reasoning:
| Constraint | The shortcut it closes |
|---|---|
| Reads go through the Baker | Reading around it works today and ships stale data later |
| No runtime archetype construction | Rebuilding the prefab’s shape in C# duplicates the authoring |
| Prefab excluded without your own filter | A manual name/flag check works and teaches nothing |
| Values authored in the Inspector | Hardcoding skips the entire dependency-tracking problem |
| No unnecessary Dynamic | You just measured what it costs; spend it deliberately |
If you find yourself wanting to violate one, that is the signal to re-read the lesson it points at rather than to route around it.
How to work it
Build the smallest failing thing and grow it. A reasonable order:
- Spawner entity exists. An authoring component and a baker that adds one component with a hardcoded count. Confirm it in the Entities Hierarchy. Nothing spawns yet.
- Count comes from the Inspector. Change it, re-enter Play, confirm the baked value changed. This is where the tracked-read question first bites.
- Prefab reference bakes. The spawner’s component now holds an
Entity. Confirm the prefab entity appears in the Hierarchy and that your gameplay queries do not see it. - Spawning works. A system reads the count and interval and instantiates.
Module 2 has opinions about where
structural changes belong. - Survives a reload. Unload and reload the SubScene. If the reference
breaks, lesson 4 tells you what a loader has to do to a stored
Entity.
Run the checks in order. Each one that fails points at exactly one reading.
When you are done
You should be able to answer these without checking your code:
- Which of your baker’s reads registered a dependency, and how would the build behave differently if one of them had not?
- Where does the prefab’s archetype come from, and how many places in your code know what components a spawned enemy has? (The correct answer is one, and it is not a C# file.)
- What did the loader do to your spawner’s
Entityfield, and what would have happened without it? - What did you choose for the prefab’s
TransformUsageFlags, and what would the wrong choice have cost per chunk? You measured that number in the last lab — use yours.
If a check fails and you cannot find the reading it points at, the drill has done its job — it located the gap. Go back, then return. The gap is the point.