Skip to content

Lesson 3 of 9 · 23m

Prefabs, Scenes, and ScriptableObjects

Use prefabs for reusable objects, scenes for composition, and ScriptableObjects for shared data without turning assets into a mess.

A Unity project becomes shippable when content stops living in exactly one scene exactly one time. The three pillars are prefabs, scenes, and ScriptableObjects. Teams usually learn them in that order, then misuse all three until production pain teaches humility.

Prefabs are object templates

A prefab stores a configured hierarchy: components, serialized references, child objects, default values. Put anything reused more than once into a prefab:

Assets/
  Prefabs/
    Actors/Player.prefab
    Actors/Goblin.prefab
    Props/Crate.prefab
    UI/DamageNumber.prefab

A prefab instance can have overrides. That is powerful and dangerous. If every instance differs, you do not have a template; you have duplicated uncertainty.

Prefab variants beat copy-paste

When a red slime is a green slime with different stats and art, use a prefab variant. The variant inherits the base structure and overrides selected properties. Copy-pasting entire prefabs means later collision fixes, animation fixes, and balance changes must be repeated by hand.

Scenes are composition, not save files

Scenes arrange concrete instances for a level, menu, or test harness. Do not store game data in a scene merely because the Inspector makes it easy. If a value is shared across scenes or belongs to design data, promote it.

A clean small-game scene layout often looks like:

Bootstrap.unity       systems, loading, persistent services
MainMenu.unity        menu UI and flow
Game.unity            level composition and gameplay root
Test_Movement.unity   isolated mechanics sandbox

ScriptableObjects are shared data assets

Use a ScriptableObject when data should live outside scenes and be referenced by many objects:

[CreateAssetMenu(menuName = "Game/Weapon")]
public class WeaponDefinition : ScriptableObject
{
    public string displayName;
    public int damage;
    public float cooldown;
    public Sprite icon;
    public AudioClip fireSound;
}

Now a designer can create assets under Assets/Data/Weapons and balance them without touching scenes or code. The key mental model: ScriptableObjects are immutable-ish definitions, not automatically a runtime save system.

Do not mutate shared assets accidentally

Changing weaponDefinition.damage during play changes the asset in the editor and contaminates every user of that definition. Runtime state belongs on instances:

var runtimeWeapon = new RuntimeWeapon(definition);
runtimeWeapon.ConsumeAmmo();

In the editor, mutations can persist after play mode. That is convenient when intentional and horrifying when accidental.

Field notes

  • Dragging a scene object into a prefab asset field creates a reference that cannot survive loading; use asset references or runtime lookup by design.
  • Keep test scenes out of release build settings. They increase build size and occasionally become accidental entry points.
  • Use prefab mode for structural edits so you do not create accidental instance-only fixes.
  • ScriptableObject events and runtime sets are useful advanced patterns, but do not adopt them before plain references stop scaling.

Was this lesson helpful?

Sign in to rate