Skip to content
Tutorials Center
My learning

Topics

Lesson 8 of 36 ยท Editor and Project Basics

Prefabs, Assets and Scenes

Learn how Unity assets, prefabs, prefab variants, overrides and scenes work, how to organize the Assets folder, and how to load scenes from code, with runnable stand-ins.

A game is made of files. Models, textures, sounds, scripts, scenes and prefabs all live in the Assets folder, and Unity connects them through references. This lesson explains the three ideas that organize that world: assets (the raw files and what Unity does with them), prefabs (reusable templates for GameObjects) and scenes (the containers for a level). Together they let you build a game from reusable parts instead of copy-pasting objects.

Assets and importing

Drop a file into the Project window and Unity imports it: it converts the file into an internal format, creates a .meta file, and shows import settings in the Inspector. Common asset types:

Type Examples Import settings you will touch
Texture .png, .jpg, .psd Texture Type (Default, Sprite, Normal map), compression, max size
3D model .fbx, .obj, .blend Scale factor, rig type, animation import
Audio .wav, .mp3, .ogg Load type, compression format
Script .cs none; compiled into assemblies
Material, shader .mat, shader graphs Surface options
Scene .unity none
Prefab .prefab none

Changing import settings never changes the original file. If you delete the generated cache (the Library folder), Unity simply imports everything again from Assets.

Organizing the Assets folder

A common layout:

TEXT
Assets/
  Art/          (Models, Textures, Materials, Sprites)
  Audio/        (Music, SFX)
  Prefabs/
  Scenes/
  Scripts/
  ScriptableObjects/
  Settings/     (render pipeline assets, input actions)
  ThirdParty/   (imported packages from the Asset Store)

Keep third-party packages in their own folder so you can update or remove them without touching your work. Special folder names have meaning: Resources (loaded by name at run time; use sparingly), StreamingAssets (copied untouched into builds), Editor (scripts that only run in the editor), and Plugins (native libraries).

What is a prefab?

A prefab is a saved GameObject, with all its components, children and settings, that works as a template. Drag a GameObject from the Hierarchy into the Project window and it becomes a prefab; the original in the scene turns blue and becomes a prefab instance. Now you can:

  • drag the prefab from the Project window into any scene to create more instances,
  • change the prefab once and every instance updates,
  • create instances from code with Instantiate(prefab).

Use prefabs for anything that appears more than once (enemies, coins, bullets, trees, UI buttons) and even for single objects that you want to reuse across scenes (the Player, the HUD, the game manager).

Overrides

An instance can differ from its prefab. If you change a value on one instance (this goblin has more health, a different color), the changed property is marked with a bold name and a blue bar: an override. In the Inspector's Overrides drop-down you can Apply an override to the prefab (everyone gets it) or Revert it (back to the template). Instances inherit all non-overridden values from the prefab.

flowchart TD
    P["Goblin prefab (health 10, speed 2)"] --> A["Instance A: no overrides"]
    P --> B["Instance B: health overridden to 30"]
    P --> C["Instance C: speed overridden to 4"]
    P -. "edit prefab speed to 3" .-> A
    P -. "edit prefab speed to 3" .-> B

Edit the prefab, and instances A and B follow; C keeps its own speed.

Prefab variants and nested prefabs

  • A prefab variant is a prefab based on another prefab: Goblin Archer as a variant of Goblin inherits everything and adds a bow. Changing the base Goblin updates the variant. Create one by right-clicking a prefab: Create > Prefab Variant.
  • Nested prefabs are prefabs that contain other prefabs, such as a Room made of Wall, Door and Torch prefabs. Each nested piece remains linked to its own prefab.

Double-click a prefab to enter Prefab Mode, a focused editing view for that prefab only; click the back arrow to return to the scene.

The prefab idea in plain C#

The rule "instances copy the template, then keep their own overrides" can be modeled in a few lines. This stand-in uses a dictionary of properties for the template, an override dictionary per instance, and a lookup that checks the override first.

C# Prefab values and overrides (stand-in)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.

Instance A follows the template for both values. Instance B follows for speed but keeps its overridden health of 30. That is the exact behavior of prefab instances in the editor.

Instantiating prefabs from code

This read-only script spawns a prefab every second at a spawn point. You assign the prefab in the Inspector by dragging it into the field:

C#
using UnityEngine;

public class CoinSpawner : MonoBehaviour
{
    public GameObject coinPrefab;     // drag the prefab here in the Inspector
    public float interval = 1f;
    float timer;

    void Update()
    {
        timer += Time.deltaTime;
        if (timer >= interval)
        {
            timer = 0f;
            Instantiate(coinPrefab, transform.position, Quaternion.identity);
        }
    }
}

Instantiate clones the prefab (or any GameObject) at a position and rotation. See Instantiate, Destroy and Coroutines for details, including cleaning up with Destroy.

Scenes

A scene (.unity file) stores a hierarchy of GameObjects. Typical projects have a main menu scene, several level scenes and sometimes a persistent "bootstrap" scene. Remember:

  • Only scenes added to Build Profiles > Scene List go into the built game. A scene not in the list cannot be loaded at run time (a very common beginner error).
  • You can have several scenes open at once in the editor (right-click a scene in the Hierarchy, Add Scene), and load them additively at run time to stream parts of a level.
  • Objects in a scene can reference assets (prefabs, materials) freely, but references between objects in different scenes are not saved. Use scripts and events to connect them.

Loading scenes from code needs the SceneManagement namespace:

C#
using UnityEngine;
using UnityEngine.SceneManagement;

public class SceneLoader : MonoBehaviour
{
    public void LoadLevel(string sceneName)
    {
        SceneManager.LoadScene(sceneName);                    // replaces the current scene
    }

    public void AddHud()
    {
        SceneManager.LoadScene("Hud", LoadSceneMode.Additive); // keeps the current scene
    }

    public void LoadLevelAsync(string sceneName)
    {
        SceneManager.LoadSceneAsync(sceneName);               // loads in the background
    }
}

Loading a scene destroys every object in the old scene unless you mark it with DontDestroyOnLoad(gameObject). That is how music players and game managers survive between levels.

Scene loading as a stand-in

A small model of a scene manager with a build list shows why a scene missing from the list cannot load.

C# A build list and scene loading (stand-in)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.

Practical tips

  • Turn every reusable object into a prefab as soon as you copy it a second time.
  • Never rename or move assets outside the editor (see the install lesson).
  • Use Assets > Find References In Scene (right-click an asset) to see what uses it.
  • Keep each scene small; split big worlds into additive scenes.
  • Use labels and clear names: Enemy_Goblin.prefab, M_Wood.mat, T_Wood_Albedo.png.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. You edit a value on the prefab asset. What happens to instances in scenes?

    Instances inherit from the prefab. Overridden properties keep their own values.
  2. 2. A scene loads fine in the editor but SceneManager.LoadScene fails in a build. What is the most likely cause?

    Only scenes in the Build Profiles scene list are included in a build.
  3. 3. What is a prefab variant?

    Variants inherit from a base prefab, so changing the base updates the variant.
  4. 4. Which call keeps the current scene and adds another one?

    Additive mode loads the new scene alongside the open ones.

Summary

  • Assets are imported files; the .meta file holds the identity and import settings.
  • A prefab is a reusable template; instances follow it except for overrides.
  • Variants extend a prefab; nested prefabs combine prefabs.
  • Scenes must be in the build list to be loaded; additive loading keeps the current scene.
  • DontDestroyOnLoad keeps an object alive across scene loads.

Next: Your First C# Script