Why a prefab is an asset and not a scene, how one edit reaches fifty copies, and what an override really does - the per-property switch that makes one instance stop listening to its prefab for good.
Subject: Unity Game Engine · 61 slides · code lesson
Open the interactive version of this deck · Homework for this lesson
Title
Unity - Lesson 2
One asset, fifty copies, and the one switch that makes a copy stop listening.
Objectives
The diagnostic scored this 1 out of 3 - the joint-lowest topic in the report. Every wrong answer came from the same place: not being certain which of two things was being edited.
Warm-up
Answer from memory before the deck tells you anything.
Discussion prompt
You have 30 enemies in a level, all copies of the same prefab. You want them all to have 50 more health. Describe every way you can think of to do it, and which one you would actually use.
Hint: One of the ways involves clicking 30 times. That one is a trap, and not only because it is slow.
Answer:
The right way: open the prefab asset, change Health, done. Every instance that has not overridden Health picks it up.
The trap: selecting all 30 in the Hierarchy and typing the new value. That works today - and it creates 30 overrides, so the next prefab change reaches none of them.
That second outcome is the whole lesson: the fast fix now is the reason the next fix silently fails.
Section
Part 1
Concept
Figure (svg): A prefab asset drawn as a mould in the Project window with arrows to five identical instances in a scene
A prefab is one GameObject - with all its components, all their values, and all its children - saved as an asset in the Project window.
Prefab — An asset holding one saved GameObject tree. It lives on disk, belongs to no scene, and acts as the master copy for every instance of it.
Unity Manual - Prefabs Prefabs
Intuition
A photograph of a coin records what one coin looked like. A mould makes coins - and if you file a notch into the mould, every coin cast afterwards has the notch.
A prefab is the mould. The copies in your scene are castings that are still connected to it: change the mould and the existing castings change too, which is more than any real mould can do.
That last part is the whole reason prefabs exist. Without the connection you would just be copy-pasting, and 'change all fifty' would mean changing all fifty.
Prediction
You save Coin.prefab, then close the scene without saving it, and open a completely different scene.
Predict first
What has happened to the prefab?
Correct: Still there, unchanged, in the Project window.
Why: A prefab is an asset: a file on disk under Assets. It is not part of any scene, which is exactly what makes it reusable across every scene in the project. Scenes come and go; the asset stays.
Concept
These are two different kinds of asset, and mixing them up leads to looking for a prefab in the Hierarchy or expecting a scene to be reusable.
| Prefab | Scene | |
|---|---|---|
| holds | one GameObject tree | many objects, plus lighting and render settings |
| file | Coin.prefab | Level1.unity |
| opened by | double-click into Prefab Mode | double-click to load it |
| reused | yes - drop it in any scene, any number of times | no - you load one at a time |
| has a camera? | only if you put one in it | usually yes |
A useful test: ask 'how many of these can be open at once?'. Any number of prefabs; one scene (plus additively loaded ones, later).
Sorting
Sort each item by where it actually lives.
Sort into buckets
Project window, or Hierarchy?
Worked example
Build the object once in the scene, then drag it into the Project window. Three things happen at that moment.
Coin.prefab appears in the Project window// the same gesture in code, from an editor script
GameObject temp = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
temp.AddComponent<CoinSpin>();
GameObject asset = PrefabUtility.SaveAsPrefabAsset(
temp, "Assets/NaruhodoLabs/Prefabs/Coin.prefab");
Object.DestroyImmediate(temp);| before the drag | after the drag |
|---|---|
| one GameObject in the scene | one asset on disk + one instance in the scene |
| white name in the Hierarchy | blue name in the Hierarchy |
| deleting it loses the work | deleting the instance keeps the asset |
| no Inspector header | Open / Select / Overrides header |
Explain it to yourself
Discussion prompt
The object you dragged did not change. Its components and values are identical. So what is the blue name telling you?
Answer:
That the object now has a link. It is no longer a free-standing GameObject - it is an instance of an asset, and Unity is tracking which of its properties still match that asset.
Blue means 'someone else has an opinion about what I should look like'. That is the whole difference, and it is why the blue objects are the ones that can be overridden.
Section
Part 2
Concept
Change a value on the prefab asset and every instance that has not overridden that property picks it up immediately - in every scene, saved or not.
There are two ways to edit the asset: double-click it to enter Prefab Mode (the Hierarchy goes dark and shows only the prefab), or select it and edit its Inspector directly.
Unity Manual - Editing a prefab in Prefab Mode Prefab Mode
Prediction
Five coins in the scene, all instances of Coin.prefab. You click Coin 1 in the Hierarchy, change its spin speed from 90 to 360, and press Play.
Predict first
What do the five coins do?
Correct: Coin 1 spins at 360, the other four stay at 90.
Why: You edited an instance, not the asset, so you changed exactly one coin - and you created an override on it in the process. This is the 'my prefab edits do not propagate' complaint, seen from the other side: the edit worked perfectly, it just never touched the prefab.
Concept
Where you clicked decides what you edited. This is the single most useful habit in this lesson: before typing a value, look at which window you are in.
| you clicked | you are editing | who is affected |
|---|---|---|
| the prefab in the Project window | the asset | every instance, everywhere |
| Prefab Mode (double-clicked the asset) | the asset | every instance, everywhere |
| an instance in the Hierarchy | that one instance | that one instance, and it becomes an override |
The Inspector looks nearly identical in all three cases, which is why this is worth checking deliberately until it becomes automatic.
Discrimination
For each outcome, decide where the person must have been clicking.
Sort into buckets
Sort by which window produced the outcome.
Worked example
The lab does this from a menu item so you can watch five coins change at once. LoadPrefabContents opens the asset in an invisible scene of its own.
// Naruhodo Labs → Lesson 02 → 2 · Edit the PREFAB
GameObject root = PrefabUtility.LoadPrefabContents(PrefabPath);
root.GetComponent<CoinSpin>().degreesPerSecond = 360f;
PrefabUtility.SaveAsPrefabAsset(root, PrefabPath);
PrefabUtility.UnloadPrefabContents(root);Open, edit, save, unload
Why: Editing the asset's components directly also works, but this is the API pair Unity guarantees: what you loaded is a real scene tree, so every normal call works on it.
| coin | spin before | spin after | why |
|---|---|---|---|
| Coin 1 | 90 | 360 | follows the prefab |
| Coin 2 | 90 | 360 | follows the prefab |
| Coin 3 | 90 | 360 | follows the prefab (not overridden yet) |
| Coin 4 | 90 | 360 | follows the prefab |
| Coin 5 | 90 | 360 | follows the prefab |
Five objects changed and you touched one file. That is the payoff, and everything else in this lesson is about not accidentally opting out of it.
Trap
Coin 3 is in front of me in the Hierarchy. I will just change it here - it is the same coin.
Hierarchy: Coin 3 -> Inspector -> Degrees Per Second: 15
result: Coin 3 spins slowly. Coins 1, 2, 4, 5 unchanged.
Coin 3 now has an OVERRIDE on that property.| what you think you did | what you actually did |
|---|---|
| changed the coin design | changed one coin |
| a one-off tweak | a permanent opt-out for that property |
| nothing to undo | an override you now have to Revert |
Decide first: is this true of all coins, or just this one? All coins means the asset. Just this one means the instance, deliberately.
Project: double-click Coin.prefab -> Prefab Mode -> Degrees Per Second: 15
result: all five coins spin slowly.
no overrides created anywhere.The Inspector tells you which one you are in: in Prefab Mode the Hierarchy is dark and shows only the prefab, and the breadcrumb at the top reads Coin.
Unity Manual - Editing a prefab via its instances Editing a prefab via its instances
Section
Part 3
Concept
Figure (svg): Diagram of a property flowing from prefab to instance, with one instance overriding it and no longer receiving updates
When you change a value on an instance, that instance stops taking that one property from the prefab. Everything else on it keeps following the asset as before.
Override — A value stored on the instance that replaces what the prefab says for that one property. The instance ignores all future prefab changes to that property.
Concept
Unity marks overrides in three places. Learn all three, because the first one you notice is usually the smallest.
If you are ever unsure whether you are looking at a prefab value or an override, open the Overrides dropdown. An empty list means this instance is following the asset on everything.
Prediction
Coin 3 has an override: spin = 15. The prefab is at 360. Now someone edits the prefab and sets it to 45.
Predict first
What does Coin 3 do?
Correct: 15. The override holds, and holds against every future change.
Why: This is the part the diagnostic caught. An override is not 'the instance wins this round' - it is 'this instance no longer takes that property from the prefab'. Until you Revert it, no prefab edit to that property will ever reach this instance again.
Invariant
Four states of the same coin. One row never changes once it is set - find it.
Step through it
Which cell stops responding, and at which frame?
The override is sticky. That stickiness is the feature (a boss enemy that keeps its own health) and the bug (thirty enemies you edited in bulk last week).
Error analysis
This is real output from the lab's step 4. One line explains a bug someone will spend an hour on.
Annotate
Notice what is not listed: position. Every instance has its own position, and Unity treats position, rotation and name as expected differences rather than overrides. Otherwise every object you ever moved would be flagged.
Comparison
Three actions, three questions. Complete it from what you now know.
Comparison matrix
| Changes the asset? | Changes other instances? | Creates an override? | |
|---|---|---|---|
| Edit the prefab in Prefab Mode | yes | yes | no |
| Edit one instance in the Hierarchy | no | no | yes |
| Apply an instance's override | yes | yes | no - it clears it |
Concept
Once an override exists there are exactly two things you can do with it.
| you want | use |
|---|---|
| this tweak was actually right for all of them | Apply |
| this tweak was a mistake | Revert |
| this tweak is right for this one only | leave it - that is what an override is for |
Apply is the one to be careful with: it rewrites the asset, so it changes every other instance in every other scene at the same time.
Elimination
A designer changed the boss enemy's health on the instance in Level 3. Everyone agrees the boss should be tougher than a normal enemy.
Eliminate the wrong options
What should happen to that override?
Survives elimination: A
Why: One deliberate difference on one instance is exactly what an override is for, and the blue bar documents it for the next person. Choice D becomes the right answer as soon as the boss differs in several ways - at that point a prefab variant (a prefab based on another prefab) is the tool, and it is worth looking up once this lesson is solid.
Counterexample
Discussion prompt
Someone says: 'If I never touch the Hierarchy, I can never create an override.' Find a way that is false.
Hint: Think about the things every instance has its own copy of.
Answer:
Moving an instance in the Scene view writes its position - and while Unity does not flag position as a normal override, adding a component to an instance, or deleting one from it, absolutely is one and is done by dragging, not typing.
A second answer: PrefabUtility.RecordPrefabInstancePropertyModifications from an editor script creates overrides with no clicking at all. The lab's step 3 does exactly that.
Section
Part 4
Concept
At runtime you cannot drag anything. Instantiate(prefab, position, rotation) is the drag, in code - one call, one new GameObject in the scene.
public class PrefabSpawner : MonoBehaviour
{
public GameObject coinPrefab; // drag the ASSET here, not a scene object
void SpawnOne(Vector3 where)
{
GameObject clone = Instantiate(coinPrefab, where, Quaternion.identity);
clone.name = "Coin (spawned)";
}
}| expression | what it is |
|---|---|
coinPrefab | the asset - one object, never changes, id stays the same |
Instantiate(coinPrefab, ...) | a brand-new GameObject, a copy of the asset |
clone | the copy - a different instance id every time |
clone.name | editable per copy; the asset's name is untouched |
Unity Scripting API - Object.Instantiate Object.Instantiate
Prediction
During Play, your code changes a spawned coin's spin to 500.
Predict first
What happens to the prefab asset?
Correct: Nothing. The asset is untouched.
Why: A runtime clone is a copy in the scene. Writing to its components writes to that copy. The 'instance edit changes the prefab' fear is exactly backwards - editing an instance never writes to the asset unless you deliberately Apply, and Apply is an editor-only action that does not exist at runtime.
Worked example
The lab spawns four coins on a timer and prints the instance ids.
GameObject clone = Instantiate(coinPrefab, where, Quaternion.identity);
Debug.Log($"spawned {clone.name} — id {clone.GetInstanceID()}, " +
$"asset id {coinPrefab.GetInstanceID()}");| spawn | clone instance id | asset id | in the scene after Stop? |
|---|---|---|---|
| 1 | -8422 (example) | -7104 | no |
| 2 | -8630 | -7104 | no |
| 3 | -8841 | -7104 | no |
| 4 | -9052 | -7104 | no |
Two facts in one table. The asset id never changes - there is only ever one asset. And nothing spawned at runtime is saved: press Stop and all four vanish, because they were never part of the scene file.
Fill the middle
Fill the two blanks so this spawns a coin one unit above the spawner.
Fill in the blanks
public class Spawner : MonoBehaviour
Instantiate}(coinPrefab, where, Quaternion.identity);
}
}
Why: Quaternion.identity means no rotation - the identity of the rotation system, the way 0 is for addition. It is the value you want whenever the spawned object should sit unrotated; transform.rotation would instead match the spawner's own facing, which is what a gun firing a bullet wants.
Ranking
Put these in the order they happen when a coin is spawned and then collected.
Put in order
Earliest first.
Why: The first two happen in the editor, before the game ever runs - which is why a missing prefab reference is a setup mistake rather than a bug in your code. Awake fires during Instantiate itself, so a freshly instantiated object has already woken up by the time Instantiate returns to you.
Trap
The Inspector slot says GameObject and there is a coin right there in the Hierarchy. Drag it in.
Spawner
Coin Prefab: [ Coin 3 (Hierarchy) ] <- a scene object
Result: it spawns copies of Coin 3, including its OVERRIDE (spin = 15),
and if Coin 3 is destroyed mid-game the field goes null.It looks like it works, which is why this one survives to a build.
Drag from the Project window. The field should hold the asset, which nothing in the scene can destroy.
Spawner
Coin Prefab: [ Coin (Project) ] <- the asset
Result: every spawn is a clean copy of the master, with no instance's
private overrides baked in.| check | how |
|---|---|
| is my reference an asset? | prefab.scene.IsValid() is false for an asset |
| in the Inspector | the little icon is the prefab's blue box, not a scene object |
| the lab does this | PrefabSpawner checks it at Start and prints PASS or FAIL |
Definition probe
Not every difference between an instance and its prefab is an override. Sort these by whether Unity treats them as one.
Sort into buckets
Override, or an expected per-instance difference?
Matching
Unity is telling you the prefab state constantly. These four cues are the whole vocabulary.
Match the pairs
Match each cue to what it means.
Why: Three of these are visible without opening a single menu, which is the point: the editor is already answering 'am I about to edit an instance?' before you click. Missing Prefab is the one worth reacting to immediately - the objects still work, but nothing you do to any asset will reach them again.
Notation
The report prints property paths, not friendly names. They are readable once you know the two conventions.
Annotate
So a report line is who : which property = what value. When a coin behaves differently from its neighbours, this is the line that says why in one glance.
Concept
Two features you do not need today but should recognise by name, because both replace piles of overrides.
| situation | the right tool |
|---|---|
| one number differs on one object | an override |
| a whole category differs (bosses) | a prefab variant |
| a part is reused across several prefabs | a nested prefab |
| thirty objects differ the same way | you have a variant, whether or not you have made one yet |
Two truths and a lie
One is false. Rule it out and say what rules it out.
Eliminate the wrong options
Which claim about Instantiate is false?
Survives elimination: B
Why: Nothing created at runtime is written back into the scene file. Play mode runs on a copy of the scene, and stopping throws that copy away - which is also why Inspector tweaks made during Play are lost, and why the editor tints itself while playing.
Reverse engineer
A teammate reports: 'I changed the enemy prefab's speed and only 8 of the 20 enemies got faster.'
Discussion prompt
What did the other 12 enemies have done to them, when, and by whom? Then say exactly what you would click to fix it.
Hint: The 8 that worked are the normal ones. The 12 are the ones with a history.
Answer:
The 12 have an override on speed, created at some earlier point by someone editing them in the Hierarchy - probably in bulk, probably while balancing.
Fix: select the 12, open Overrides in the Inspector, and Revert the speed override. If their tuned values were the good ones, Apply one of them to the prefab first, then Revert the rest onto it.
Then check whether those 12 are really a category - if they are all the 'elite' enemies, they want a variant rather than twelve overrides.
Section
Build
Concept
A coin prefab, five instances, one deliberate override, and a report that prints exactly which instance is ignoring which property.
Unlike lesson 1, most of this happens with the game stopped - prefabs are an editor feature, and the interesting moments are all edits.
| menu step | what it proves |
|---|---|
| 1 · Build scene + Coin prefab | one asset, five linked instances |
| 2 · Edit the PREFAB (90 to 360) | one edit reaches all five |
| 3 · Override ONE instance (to 15) | the blue bar appears on one coin |
| 4 · Report overrides | which property, on which instance |
| 5 · Edit the PREFAB again (to 45) | four follow, the overridden one does not |
| 6a / 6b · Apply / Revert | the two ways to clear an override |
Step zero
Discussion prompt
Before opening Unity: what is the smallest set of steps that proves an override is permanent rather than one-time? Write them in order.
Hint: You need at least two prefab edits, with the override created between them.
Answer:
Step 4 is the one people skip, and it is the only step that distinguishes 'the override won this round' from 'the link is cut'.
Worked example
Do it by hand first: build a cylinder coin, attach CoinSpin, drag it into Assets/NaruhodoLabs/Prefabs.
public class CoinSpin : MonoBehaviour
{
public float degreesPerSecond = 90f;
public float bobHeight = 0.25f;
void Update()
{
transform.Rotate(Vector3.up, degreesPerSecond * Time.deltaTime, Space.World);
}
}Time.deltaTime is doing real work on line 8
Why: 90 degrees per SECOND, not per frame. Without it the coin spins at a different speed on every machine - the misconception the diagnostic checked separately.
| step | where you click | coins affected |
|---|---|---|
| drag Coin into Project | Hierarchy to Project | creates the asset; the dragged one becomes an instance |
| drag the asset back in, 4 more times | Project to Hierarchy | 5 instances |
| double-click the asset, set 360 | Prefab Mode | all 5 |
Worked example
Now click Coin 3 in the Hierarchy and set its spin to 15. Then run the report.
// what the report does, per instance
PropertyModification[] mods = PrefabUtility.GetPropertyModifications(coin);
foreach (PropertyModification mod in mods)
{
if (mod.propertyPath.StartsWith("m_LocalPosition")) continue; // expected per-instance
Debug.Log($"{coin.name} overrides {mod.propertyPath} = {mod.value}");
}Line 5 filters out the 'default overrides'
Why: Position, rotation and name differ on every instance by design. Unity does not colour them blue, and neither does this report.
| coin | reported overrides | spin now |
|---|---|---|
| Coin 1 | none | 360 |
| Coin 2 | none | 360 |
| Coin 3 | degreesPerSecond = 15 | 15 |
| Coin 4 | none | 360 |
| Coin 5 | none | 360 |
Hypothesis
You are about to edit the prefab from 360 to 45, with Coin 3 overridden at 15.
Predict first
Write down the five values you expect before you click.
Correct: 45, 45, 15, 45, 45
Why: Four coins follow the asset and take 45. Coin 3 keeps 15 because its link for that property was cut when you typed a value into the instance. Predicting before clicking is the habit that turns this from a rule you memorised into a model you can use.
Real world
Discussion prompt
Your team has 60 enemies across 4 levels, all from one prefab. Someone spent an afternoon 'balancing' by selecting groups in the Hierarchy and typing new health values. Two weeks later the designer changes the prefab's health and nothing happens. Explain what is wrong and how you would fix all 60.
Answer:
Every enemy they touched now has an override on Health, so the prefab edit reaches none of them.
The fix: select the affected instances, open the Overrides dropdown and Revert the Health override on each - or, if the balanced values were the good ones, pick one and Apply it so the asset carries the new number and the rest can be reverted onto it.
The prevention: balance values in Prefab Mode. If a subset genuinely needs different numbers, that subset wants a prefab variant, not sixty overrides.
Explain it
Discussion prompt
Explain to someone who has never used Unity what a prefab is and what an override is - two sentences, no jargon beyond those two words.
Answer:
Model answer: 'A prefab is a saved copy of an object kept in a file, and everything you drop into the level from it stays connected, so changing the file changes all of them.'
'An override is when you change one of those copies directly - that copy keeps your value and stops taking that setting from the file, permanently, until you tell it to go back.'
Concept
Each takes under a minute and kills one wrong belief.
| do this | what you expect | what happens |
|---|---|---|
Delete Coin.prefab while five coins are in the scene | the coins vanish | they survive; the header reads Missing Prefab |
| Ask which scene the prefab is in | the current one | none - it is an asset |
| Add a Rigidbody in Prefab Mode | only the prefab changes | all five coins fall - structure propagates too |
| Apply Coin 3's override | only Coin 3 changes | the asset changes, so all five become 15 |
Pattern
Four questions, in order. They take three seconds and prevent the entire category of bug this lesson is about.
And when a subset needs several differences, stop overriding and make a prefab variant - a prefab whose parent is another prefab. It is the supported way to say 'like that, but'.
Check
Answer before you click.
Check your understanding
Which statement describes a prefab most accurately?
Answer: B
Why: A prefab is a file under Assets holding one GameObject with all its components, values and children. It belongs to no scene, can be used in every scene, and every instance stays linked to it - which is what makes one edit reach fifty objects.
Check
Five instances in the scene, none of them overridden.
Check your understanding
You want all five coins to spin faster. Which action does that, and only that?
Answer: B
Why: Editing the asset is the only action that changes all five without leaving overrides behind. Every coin that has not overridden that property picks the new value up immediately, in this scene and every other one.
Socratic
Discussion prompt
Unity could have made prefab edits win over instance edits, so the asset always dictated. Why would that be worse?
Answer:
Because every real level needs exceptions: this one door is locked, this one enemy is the boss, this one lamp is broken. Without per-instance overrides you would need a separate prefab for every exception.
The cost of that flexibility is precisely the trap in this lesson: a mechanism that lets you say 'this one is different' cannot also stop you saying it by accident. Hence the blue bar - Unity's attempt to make the exception visible.
Check
The one the diagnostic missed. Take your time.
Check your understanding
Coin 3's spin was overridden to 15 while the prefab said 360. The prefab is now changed to 45, then later to 120. What does Coin 3 read?
Answer: B
Why: An override cuts the link for that property permanently. Coin 3 will read 15 through every future prefab change until someone Reverts the override or Applies it. 'Permanent until reverted' is the phrase worth memorising.
Estimation
A level has 200 coins from one prefab. You change the prefab's mesh.
Predict first
Roughly how many objects do you have to touch by hand?
Correct: One: the asset. Every instance that has not overridden the mesh follows.
Why: The answer being one is the entire economic argument for prefabs, and it is why the override trap matters so much - a project where half the instances are accidentally overridden has quietly lost that property and is back to touching things by hand.
Concept
Almost everything you spawn in a game comes from a prefab: bullets, enemies, pickups, particle effects, UI popups. Lesson 5 is about the call that spawns them.
| you now have | what it enables |
|---|---|
| an asset with a link | one edit reaches every copy |
| overrides | deliberate exceptions, visible in the Inspector |
Instantiate | objects created while the game runs |
| the Overrides dropdown | a way to audit what a scene has quietly changed |
Analogy
If you have used styles in a word processor, or a class in CSS, you already have the model.
Match the pairs
Match each Unity idea to its closest cousin.
Why: The failure mode is the same too: a document where everyone hand-formatted instead of using styles is a document where changing the style does nothing, which is exactly a project full of accidental overrides. Recognising the pattern means the fix transfers as well as the problem.
Connect it up
Draw it
Draw one prefab asset on the left and three instances on the right, with an arrow from the asset to each. Cut one arrow with a cross and label what that instance now ignores - and what it still follows.
Exit ticket
Predict first
Which is still shakiest?
Correct: Whichever you picked - open the lab and run the six menu steps for that one.
Why: This was the joint-lowest topic in the diagnostic at 1 out of 3, so a shaky spot here is expected rather than embarrassing. Name it, then run the lab's step sequence: it was built to make each of those four visible in under a minute.
Recap
You can tell, before clicking, whether an edit will reach one object or fifty.
Instantiate(prefab, position, rotation) is the runtime version of the drag - and nothing it creates is savedLab: unity-labs/Assets/NaruhodoLabs/Lesson02_Prefabs/SETUP.md. Run all six menu steps in order, then go to lesson 3.
Want this taught 1-on-1? Alexander tutors Unity Game Engine — $55/session, free consultation.