Overview

A Prefab is a reusable GameObject asset stored in the Project window. It lets a team define a coin, enemy, projectile, UI widget, or particle effect once, then create instances wherever needed. Prefabs are one of Unity’s most important workflow features because they turn repeated scene objects into reusable assets instead of manual duplication. (course lab series, see source-csharp-unity-labs)

Setup

Typical prefab workflow:

  1. Build and configure a GameObject in a scene.
  2. Drag it into the Project window to create a prefab asset.
  3. Use that prefab in scenes or via runtime instantiation.

Key distinction:

ThingMeaning
Prefab assetThe reusable source definition in the Project window
Prefab instanceA copy placed in a scene or spawned at runtime

Usage

Prefabs are best for:

  • repeated enemies or pickups
  • reusable UI elements
  • particle/VFX bundles
  • projectiles and spawned hazards

The scripting counterpart is unity-prefabs-scripting, which covers Instantiate, tracking lists, and despawning.

Gotchas

  • Editing a prefab asset can change many scene instances at once.
  • Instance overrides can make one scene object behave differently from the source prefab; that is useful, but easy to forget when debugging.
  • Prefabs solve reuse, not communication. Scripts on prefab instances still need references, events, or managers to integrate with the rest of the game.

Worked example

The beginner 2D route turns a Coin into a prefab and spawns copies of it at marked points:

  • PickupSpawner.cs — instantiates a coin prefab at each spawn point and parents the clones under one object; the folder’s README gives the scene set-up

Practice

Make a Coin prefab and test how changes travel between the asset and its instances:

  • build a coin in the scene (sprite plus a trigger collider), then drag it into the Project window to create the prefab asset
  • delete the original and place three instances of the prefab in the scene
  • change the colour of one instance only in the Inspector
  • open the prefab asset and change its scale

Success test:

  • all three instances pick up the new scale
  • the instance you recoloured keeps its own colour, and the changed field is shown in bold as an override
  • you can say which object in the Project window is the asset and which objects in the Hierarchy are instances

Extension:

  • use the instance’s Overrides drop-down to revert the colour, then apply a different change from an instance back to the asset, and observe the effect on the other two coins

Self-test

  1. What is the difference between a prefab asset and a prefab instance?
  2. How do you turn a configured scene object into a prefab asset?
  3. You change the sprite on the prefab asset. What happens to the coins already placed in your scenes?
  4. One enemy behaves differently from all the others made from the same prefab. What should you check first?
  5. Your coin prefab must add to the score when collected. Does making it a prefab solve how it reaches the score?

Answers

  1. The asset is the reusable source definition stored in the Project window; an instance is a copy of it placed in a scene or spawned at runtime.
  2. Drag the GameObject from the Hierarchy into the Project window.
  3. They all change with it, because editing the asset can change many scene instances at once.
  4. Whether that instance has overrides that make it differ from the source prefab.
  5. No. Prefabs solve reuse, not communication; the coin still needs a reference, an event or a manager to reach the score.

unity-prefabs-scripting · unity-inspector-references · unity-object-communication · unity-particle-system-scripting · source-csharp-unity-labs · unity-scene-management