How does a prefab instance placed in a level store its differences from the prefab, and what breaks with nested prefab overrides?
answer
- reference plus a delta
- property path and value
- stable IDs, not names
- closest layer to the placement wins
basics
~20 sAn instance stores a reference to the prefab plus overrides: property paths and new values, keyed by stable object IDs. Prefab edits reach every instance except overridden properties; nested prefabs stack overrides, with the layer nearest the placed instance usually winning.
solid answer
~50 sA prefab is a reusable template — a small hierarchy of objects, components and property values saved as an asset. Placing one stores a **reference to the prefab**, the instance's transform and a list of **overrides**: `(object ID, property path, value)` entries, plus added or removed objects. When the prefab changes, every instance re-resolves from it, so the change propagates except where an override shadows it. With **nesting** (a door prefab inside a house prefab inside a level), values resolve in layers: the door's defaults, then the house's overrides on the door, then the level's overrides on that house instance, with the outer layer winning in the usual design. What breaks: overrides keyed by child name or index retarget or orphan when children are renamed or reordered; accidental overrides silently stop propagation; overrides on deleted children dangle; and editing a widely used prefab rewrites thousands of placements, so many pipelines flatten instances into plain objects at cook time.
code
json · 11 lines{
"prefab": "asset:7c41e2d0",
"instanceId": "inst:a91e",
"transform": { "position": [120.0, 0.0, -48.5], "yawDegrees": 90 },
"overrides": [
{ "target": "obj:3b07", "property": "lamp.intensity", "value": 0.4 },
{ "target": "obj:77d2/obj:0c15", "property": "door.locked", "value": true }
],
"addedObjects": [],
"removedObjects": ["obj:91aa"]
}go deeper
Recall that a prefab is a reusable template and an instance stores a reference to it plus the properties it changed.
Explain overrides as property paths keyed by stable IDs, how nested overrides resolve in layers, and why name- or index-keyed overrides break.
Diagnose instances that stopped receiving prefab fixes as accidental overrides, and plan how dangling overrides and widely shared prefab edits are detected and handled.
Set the team's prefab rules — nesting depth, override visibility, cook-time flattening, treating structural prefab edits as schema changes — weighing designer freedom against level maintenance.
## What a prefab is A **prefab** is an authored template: a small hierarchy of objects with their components and property values, saved as an asset so it can be placed many times. A watchtower prefab might hold the tower mesh, a ladder, a lamp and a guard spawn point. Most engines have this idea under one name or another; the details of their editors differ, but the data model underneath is broadly shared. Placing a prefab in a level creates a **prefab instance**. The important design decision is that the instance does **not** copy the template's data. It stores: - a **reference** to the prefab asset, usually by a stable asset ID rather than a file path; - the instance's own **transform** in the level; - a list of **overrides**, each one an object identifier inside the prefab, a property path and a new value; - structural changes: objects **added** to this instance or **removed** from it. The JSON example with this answer shows that shape. Everything not overridden is read from the prefab when the level loads or when the editor resolves the instance. ## Why store a delta Storing a delta has two consequences that matter: 1. **Propagation.** Fixing the watchtower's ladder in the prefab fixes all three hundred placed watchtowers, because none of them stored their own ladder. 2. **Small level data.** A placed instance is a reference, a transform and a handful of overrides, which keeps level files small and diffs readable. Placing thousands of identical objects — trees, rocks, fence posts — can work the same way: each placement holds only its transform and overrides, and the shared data is stored once. Drawing many copies cheaply on the GPU is a separate rendering technique, also called instancing, and is covered with rendering. ## How nested overrides resolve Prefabs may contain other prefab instances: a door prefab inside a house prefab, with houses placed in a level. A property on the door then has several possible sources, resolved in layers: 1. the door prefab's own value; 2. the house prefab's override on its door instance; 3. the level's override on that particular placed house, reaching down into the door. In the usual design the **outer layer wins**: the level designer who places a house and locks its door gets a locked door, even though the house prefab says unlocked. Editors let you push an override down a level ("apply to the house prefab") or revert it. ## What breaks - **Unstable targets.** If an override names its target by child name or child index, renaming or reordering children in the prefab silently retargets it to the wrong object or orphans it. Overrides must target **stable per-object IDs** assigned when the object is created inside the prefab and never reused. - **Accidental overrides.** Nudging a value and nudging it back can still leave an override recorded, and that property then ignores every future prefab edit. Tools should drop overrides equal to the inherited value and make overrides visible. - **Dangling overrides.** If the prefab author deletes an object that instances override, those overrides point at nothing; the loader must report and discard them rather than fail or guess. - **Ambiguous edits.** With three layers, an edit made while viewing the level could belong to the level, the house or the door. Editors must make the target layer explicit, or overrides land in the wrong place. - **Propagation cost.** Changing a prefab used across hundreds of levels means re-resolving and, in many pipelines, re-saving or re-cooking all of them. ## Flattening for the shipped game Resolving overrides is editor-time convenience. Many pipelines **flatten** instances during the cook: each placed instance becomes plain objects with final values, so the shipped game never walks prefab layers at load time, and the prefab's internal structure stops mattering at run time. | Concern | Edit time | Shipped game | |---|---|---| | Prefab reference | kept, resolved on load | often removed by flattening | | Overrides | stored per instance | baked into final values | | Shared data | stored once in the prefab | stored once, referenced by placements | Rules a team usually adopts: overrides must be visible and revertible, keep nesting shallow, and treat a structural change to a widely used prefab like a schema change.
- A prefab author deletes a child object that hundreds of placed instances override. What should the tools do?Detect the dangling overrides when instances are resolved, report them with the level and instance they belong to, and discard them rather than retargeting by name or index. Ideally the editor warns before the delete, listing how many placements override that object, so the author can decide whether to migrate the overrides first.
- Why do many pipelines flatten prefab instances when cooking a level?Layered override resolution is an editing convenience with a load-time cost. Baking each instance into plain objects with final values makes loading a straight read, removes prefab assets the level no longer needs at run time, and avoids surprises from resolution order differing between editor and game.
- Each prefab instance stores a full copy of the prefab's data.
- Editing a prefab overwrites every instance, including overridden properties.
- Overrides can safely target child objects by name or by child index.
- The innermost nested prefab's value always beats the placed instance's override.
- Prefab instancing and GPU instanced drawing are the same feature.