Course contentsShow
← Unity Game Development
Lesson 18 of 8281. Unity FoundationsFree lesson

Creating Prefabs for Reusable Object Templates

Convert complex GameObject structures into Prefabs to maintain consistent instances across multiple scenes and streamline your development workflow.

In this lesson, you will learn how to turn complex GameObject hierarchies into Prefabs to create reusable, consistent templates that stay synchronized across your entire project.

Why Use Prefabs?

Imagine you have spent time building a complex "Enemy" character. You’ve assembled a base GameObject, attached several child objects for visual flair, added a Collider, and linked a custom script for movement. If you want ten of these enemies in your scene, copying and pasting them is tedious. Worse, if you decide to change the enemy's speed later, you would have to update all ten individually!

A Prefab solves this by turning your configured GameObject into a "master template" stored in your Project window.

How to Create a Prefab

Creating a Prefab is incredibly straightforward:

  1. Ensure your GameObject (and its children) is perfectly configured in your Hierarchy.
  2. Click and drag the GameObject from the Hierarchy directly into your Project window (the folder where your assets live).

Once you do this, you will see a new file icon appear. The GameObject in your hierarchy will turn blue, indicating it is now an instance connected to that Prefab.

Managing Changes

When you want to edit your Prefab, you can double-click the Prefab asset in your Project window to enter Prefab Mode. Any changes you make here—like adjusting a component property or adding a new child object—will automatically update every single instance of that object throughout your scenes.

For example, if you change a value in your script:

// Inside your Enemy script component
public float moveSpeed = 5f; 

Changing this value within the Prefab template ensures that all enemies in your game reflect the new speed instantly. This keeps your development workflow clean and prevents the errors that come from manually updating dozens of identical objects.

If you ever need an object to be unique, you can right-click the instance in the Hierarchy and select "Prefab" > "Unpack," which breaks the link to the template, turning it back into a standard, independent GameObject.

Key Takeaway: Prefabs serve as your master templates, allowing you to propagate changes to hundreds of object instances simultaneously by editing just one central asset.