menu_bookDocumentation

Prefabs - s&box Documentation

calendar_today May 5, 2026 schedule ~2 min read person patrickjr verified 50

Prefabs

Prefabs are reusable GameObject templates that allow you to create consistent, repeatable objects across your game. You create a prefab asset from a GameObject in your scene, then instantiate it multiple times. Changes to the prefab asset propagate to all instances, while individual instances can have overrides.

Creating Prefabs

In Editor

  1. Select the GameObject you want to make into a prefab
  2. Right-click and select Create Prefab From Selection
  3. Choose a location and name for your prefab file
  4. The original GameObject becomes an instance of the prefab

Prefab Assets

Prefabs are saved as .prefab files in your project. They appear in the Asset Browser and can be organized into folders like any other asset.

Instantiating Prefabs

In Code

CSHARP
// Instantiate a prefab into the scene
var instance = myPrefab.Clone();
instance.WorldPosition = spawnPosition;

// Or clone with a specific parent transform
var instance = myPrefab.Clone( parentTransform );

// Load and instantiate in one line
var enemy = Resource.Load<PrefabFile>( "prefabs/enemy.prefab" ).Clone();

Runtime Prefab Creation

You can also create prefabs at runtime from existing GameObjects:

CSHARP
// Create a prefab from an existing GameObject at runtime
var runtimePrefab = new PrefabFile();
runtimePrefab.UpdateFrom( sourceGameObject );

// Then instantiate it multiple times
var copy1 = runtimePrefab.Clone();
var copy2 = runtimePrefab.Clone();

Prefab Variants

Prefabs support variants that override specific properties while keeping the base prefab connection. This is useful for creating variations of enemies, items, or environmental objects.

  1. Right-click a prefab in the Asset Browser
  2. Select Create Variant
  3. Modify properties on the variant without affecting the base prefab

Instance Overrides

When you have a prefab instance in a scene, you can override specific properties:

  1. Select the prefab instance
  2. Modify properties in the Inspector
  3. The modified values show as bold (indicating overridden)
  4. Right-click properties to revert or apply overrides to the prefab asset
Was this helpful?