Unity Foundations·From empty scene to playable build

Scenes and prefabs

Organise a scene hierarchy and reuse objects with prefab assets, variants and runtime instantiation.

Beginner 12 min read Lesson 2 of 300 Challenge included
What you will be able to do
  • Turn any repeated GameObject into a prefab.
  • Use prefab variants to share a base while varying details.
  • Instantiate prefabs from a script at runtime.

In plain English

A scene hierarchy is a tree of GameObjects, and the parent and child relationship lets you move and organise whole groups at once. A prefab is a reusable asset that stores a GameObject with its components and settings, so you edit it once and every copy updates. Instantiating means creating a copy of a prefab at runtime, usually from a script, and a prefab variant is a child prefab that inherits from a base prefab while overriding a few values. Prefabs matter because they keep repeated objects such as enemies and pickups consistent and easy to change.

Step by step

  1. 1Create a GameObject and add the components it needs.
  2. 2Drag it into the Project window to create a prefab asset.
  3. 3Create a prefab variant and override one property.
  4. 4Write a script that instantiates the prefab at runtime.
Spawner.csC#
using UnityEngine;

public class Spawner : MonoBehaviour
{
    [SerializeField] private GameObject enemyPrefab;

    private void Start()
    {
        Instantiate(enemyPrefab, transform.position, Quaternion.identity);
    }
}

Common mistakes

  • Editing a copy in the scene only changes that copy; to update every copy you must edit the prefab asset itself.
  • Overriding a property on an instance breaks its link to the prefab for that property, so later prefab edits will not reach it.
  • Instantiating in Update without a limit can create hundreds of objects per frame and freeze the game.
  • Leaving many unused objects as separate scene copies instead of prefabs makes future changes slow and error-prone.
Your turn

Spawn a prefab

Easy

Write a Spawner that instantiates an enemy prefab at its own position when the scene starts.

CSHARP · starter
using UnityEngine;

public class Spawner : MonoBehaviour
{
    [SerializeField] private GameObject enemyPrefab;

    private void Start()
    {
    }
}
Check your understanding before moving on.
Knowledge checkQuestion 1

You edit a prefab asset after placing several instances. What happens?

Select an answer to continue
Study tools

Make it yours.

Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.

Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Lesson 2 of 300 · 0% of course