Skip to main content
Version: Next (dev)

Prefabs

A prefab is a group of objects saved as an asset (.plPrefab) so that you can place it many times. A lamp post, a door with its trigger, or an enemy with its weapon are typical prefabs. When you change the prefab, every place that uses it follows.

You open a prefab like any other document. The prefab editor looks like the scene editor: it has a scene tree, Properties, the 3D view and, beside Properties, the Prefab Settings tab (the prefab's exposed parameters) and the Variant tab (see Prefab Variants).

Creating a prefab​

  1. In a scene, select the objects that make up the prefab.
  2. Right-click them in the scene tree or the viewport and choose Prefabs > Create Prefab....
  3. Pick where to save the .plPrefab file.

The selected objects are replaced by an instance of the new prefab.

Editor prefabs and engine prefabs​

A prefab can be placed in two ways. Both reference the same prefab asset.

Editor prefab instanceEngine prefab instance
What the scene storesA copy of the prefab's objects, remembered as coming from the prefab.One object with a Prefab Reference component. The objects are created when the scene runs.
Per-instance changesAny property of any object of the instance can be changed. The changes are kept when the prefab is updated.Only the prefab's exposed parameters, under Parameters of the Prefab Reference component.
How to place itHold SHIFT while you drag the prefab from the asset browser.Drag the prefab from the asset browser.
CostEvery instance is saved in full in the scene.Small: the scene stores the reference and the parameters.

Use engine prefabs for anything placed many times. Use editor prefabs when individual instances need hand changes that you can't express as parameters.

The Prefabs menu​

Right-click a prefab instance in the scene tree or the viewport and open Prefabs:

EntryWhat it does
Edit Prefab...Opens the prefab in its own window.
Revert PrefabThrows away the changes an editor prefab instance made, so it matches the prefab again.
Create Prefab...Makes a new prefab from the selected objects.
Create Variant...Makes a variant of the instance's prefab.
Switch VariantSwitches the selected instances to another prefab of the same family.
Save Overrides as Variant...Writes the changes of an editor prefab instance into a new variant.
Open Variant ZooOpens a scene with one instance of every prefab of the family.
Unlink from TemplateTurns the instance into ordinary objects with no connection to the prefab.
Convert to Editor PrefabTurns an engine prefab instance into an editor prefab instance.
Convert to Engine PrefabTurns an editor prefab instance into an engine prefab instance.

In a prefab document the menu also has Remove Base Prefab, see Prefab Variants.

Prefabs at runtime​

The Spawn component instantiates a prefab while the game runs, at intervals or when told to. Code can instantiate prefab resources directly as well. Both the Prefab Reference and the Spawn components can pick a random prefab of a family each time, see Randomize Variant on Spawn.

See Also​