Learn how to create prefabs, apply changes via Overrides, and build nested prefabs.
You are making a warehouse simulator. The warehouse contains shelves, and on them — boxes. Boxes can hold different products, but all boxes share the same base (model, Rigidbody component, BoxSound script).
- Create a
Cubein the scene (GameObject → 3D Object → Cube). - Add a
Rigidbodycomponent. - Add an
Audio Sourcecomponent (sound when falling). - Attach a
BoxSoundscript (imagine it exists — just add an empty dummy script). - Rename the object to
Box_Base. - Drag
Box_Basefrom the Hierarchy into the Project window into aPrefabsfolder (create it if needed). It is now a prefab.
- Create an empty GameObject → name it
Shelf_Base. - Create 3 vertical cubes (shelf legs) and 2 horizontal cubes (shelves) — arrange them neatly.
- Now the key part: drag 4 instances of
Box_Basefrom the Project window onto the shelves (insideShelf_Baseas child objects). - Select the parent object
Shelf_Baseand drag it into the Project window → aShelf_Baseprefab is created, which contains theBox_Baseprefab inside. This is a nested prefab.
- Drag 3 instances of
Shelf_Basefrom the Project into the Hierarchy (three different shelves in the scene). - On the second shelf, select one of the boxes (the child
Box_Baseobject). - In the Inspector, change its material color to red (or scale it to (1.5, 1.5, 1.5)).
- This instance now has an Override (the
Overridesbutton on the parentShelf_Basebecomes active). - Click
Overrides→Apply All. What happened to the boxes on the other shelves? (They also became red/large).
- Double-click
Box_Basein the Project window → Prefab Mode opens. - Increase the box size from (1,1,1) to (1.2, 1.2, 1.2).
- Click
Saveand close Prefab Mode. - Look at all the shelves in the scene. What changed? (All boxes became slightly larger — except those that had their scale overridden? Check!)
- Select the third shelf in the Hierarchy.
- Right-click →
Prefab→Unpack Prefab(fully detach). - Now delete one box from this shelf. Will boxes on other shelves be deleted? (No, the connection is gone).
- What happens if, after Step 3 (where we applied red color), we change the original
Box_Basecolor to blue? - What is the difference between
Unpack PrefabandUnpack Prefab Completely? - Why are nested prefabs useful in a real project?
You should have a scene with multiple shelves where changing one prefab updates all linked instances, while overrides work locally until applied.