Skip to main content
Version: Next (dev)

Prefab Variants

A prefab variant is a prefab that has another prefab as its base. The variant starts as an exact copy of its base and keeps only what you change in it: its overrides. When the base changes, the variant follows and keeps its overrides on top.

Typical uses are a brass, an iron and a broken version of the same lantern, or the same crate with different contents. You build the lantern once. Each variant only stores what makes it different, so a fix to the base prefab reaches all of them.

A prefab variant open in the prefab editor: the Variant Browser below the 3D view shows the Lantern base prefab and its variants as thumbnails with New Variant... and Variant Zoo buttons, and the Variant tab sits beside Properties and Prefab Settings

Families​

A base, its variants, and their variants form a family. All prefabs of a family share the same objects, so an instance of one can be switched to any other and keep the changes it made. A variant can itself be the base of further variants; each level adds its own overrides.

Creating a variant​

There are three ways:

  • Right-click a prefab instance in a scene and choose Prefabs > Create Variant.... In a prefab document, the same entry makes a variant of the open prefab.
  • In the Variant Browser, click New Variant..., or right-click a thumbnail and choose Create Variant of This Prefab....
  • Select an editor prefab instance that you have already changed in a scene and choose Prefabs > Save Overrides as Variant.... The instance's changes become the overrides of the new variant, and the object becomes an instance of it.

The editor suggests a file next to the base, named <Base>_Variant.plPrefab (then _Variant2 and so on). The new variant has no overrides yet and opens in its own window.

An existing prefab without a base can be made a variant too: open it, go to the Variant tab and click Set Base Prefab....

Editing a variant​

Open the variant and edit it like any prefab. Everything you change compared to the base is an override:

  • a property set to another value,
  • an object added,
  • an object of the base removed.

The scene tree shows where each object comes from. Objects that are as the base has them are dimmed. Objects the variant changed show a badge with the number of changes, such as 2 CHANGES, and objects only the variant has show ADDED.

A variant's exposed parameters follow its base.

The Variant tab​

The Variant tab sits beside Properties and Prefab Settings in the prefab editor. At the top it shows the Base, with:

ButtonWhat it does
OpenOpens the base prefab.
Change...Picks another base. The overrides are made again on the new base.
RemoveRemoves the base, see Removing the base.
Revert AllRemoves every override, so the prefab becomes the same as its base.

Below that is one row per override. Each row says what was changed (for example Body: Mesh > Color) and how (for example Brass -> Iron, or added or removed). Every row has two buttons:

  • Revert removes that override, so the object takes the base's value again.
  • Apply to... makes the change part of a prefab further up. The menu lists the base and every prefab above it that has the object. The chosen prefab is changed and saved, and every other variant of it gets the change too, unless it sets its own value.

The … menu of a property in Properties has the same apply entries: Apply to 'Prefab' for each prefab above the variant that has the object.

Removing the base​

Prefabs > Remove Base Prefab (or Remove in the Variant tab) cuts the link to the base. The prefab keeps its objects as they are and no longer follows the base. It is then an ordinary prefab.

The Variant Browser​

The Variant Browser panel sits below the 3D view of scenes and prefabs. It shows a thumbnail for every prefab of a family, the top prefab first, each followed by its variants.

  • In a scene, select a prefab instance. The browser shows its family and marks the prefab the instance uses. Click another thumbnail to switch the selected instances to that prefab. Prefabs > Switch Variant in the context menu does the same. The instances keep what they changed.
  • In a prefab, the browser shows the prefab's own family. Click a thumbnail to open that prefab. Right-click a thumbnail and choose Use as Base of 'Prefab' to make it the open prefab's base.

The buttons at the top of the panel are Variant Zoo, New Variant... and, when the selection has a Prefab Reference or Spawn component, Randomize on Spawn. The thumbnail context menu has Switch Selection to This Prefab, Edit Prefab... (or Open in a prefab), Create Variant of This Prefab... and, with Randomize on Spawn on, In Random Pool.

The Variant Zoo​

Variant Zoo (in the Variant Browser, or Prefabs > Open Variant Zoo) opens a scene with one instance of every prefab of the family side by side, each with its name: a row for the top prefab, one for its variants, one for their variants. Use it to compare the variants and spot one that went wrong.

The zoo is made anew every time you open it. Prefabs that changed since they were last transformed are transformed first, so the zoo shows them as they are now. The scene is written to the project's AssetCache/VariantZoo folder, it is not part of the project's assets, and it never asks to be saved.

Randomize Variant on Spawn​

The Prefab Reference and Spawn components can instantiate a random prefab of a pool instead of their own prefab. Use it to fill a scene with varied props or to spawn different enemies from one spawner.

  1. Select the object with the Prefab Reference or Spawn component.
  2. Turn on Randomize Variant on Spawn, in the component's properties or with Randomize on Spawn in the Variant Browser. An empty Variants list is filled with every prefab of the family, each with weight 1.
  3. Adjust the Weight of each entry, or add and remove entries. In the Variant Browser, each thumbnail shows its chance, and In Random Pool in its context menu adds it to or removes it from the list.
PropertyDefaultDescription
Randomize Variant on SpawnoffInstantiates one of the Variants in place of the prefab, picked by weight. While you edit the scene, the component shows its own prefab.
Variant SeedSame every runPrefab Reference only. Same every run picks from the object's stable random seed, so the same object gets the same prefab every time its scene loads. New on every spawn picks again every time it is instantiated.
VariantsemptyThe prefabs to pick from. Each entry has a Prefab and a Weight (default 1). A weight of 0 is never picked.

The Spawn component picks again on every spawn. The exposed parameters of the component are passed to whichever prefab is picked. If the list is empty or every weight is 0, the component's own prefab is used.

Troubleshooting​

SymptomCause and fix
Prefabs > Save Overrides as Variant... is disabled.It works only for editor prefab instances. Convert an engine prefab instance with Prefabs > Convert to Editor Prefab first.
Apply to... says No prefab above this one has the object.The override belongs to an object the variant added. Apply the added object itself to the base first, or keep the change in the variant.
The Variant Browser says No prefab selected.Select an object that is, or belongs to, a prefab instance.
Randomize on Spawn is missing in the Variant Browser.The selection has no Prefab Reference or Spawn component, for example an editor prefab instance.
The Variant Zoo shows an older state of a prefab.The prefab failed to transform. The log has a Variant Zoo: ... could not be transformed warning.

See Also​