A prefab variant is a Prefab that extends other Prefab. This is a concept similar to the Unity Engine prefab variants so we use the same name. However, like everything else in the Scene Editor, the best way to understand the prefab variant is looking into the generated code. Then you realize that a variant of a Prefab is a sub-class of the Prefab class.
A prefab variant inherits the properties and values of the base Prefab, however, you can unlock the properties and modify them.
Learn more about unlock a prefab property.
You can create a prefab variant very easy, the only thing you need is to use a Prefab as the prefab object of the Prefab file.
Let’s say we want to create a purple-skinned prefab variant of the Dragon Prefab. These are the steps:
-
Create a new Prefab file, name it PurpleDragon. Learn how to create a prefab file.
-
Drop the Dragon Prefab on the scene. This creates a prefab instance that is the prefab object of the file.
-
Unlock the texture property of the object and change it to the purple dragon texture. Save the file.
-
Open the Level scene file, and look in the Blocks view there are the Dragon Prefab and the PurpleDragon Prefab. Drop the PurpleDragon Prefab on the scene. It will create a new, purple, prefab instance.
-
But you want to reduce the size of both dragons. To do this, you change the scale of the X-axis of the Dragon Prefab. It will affect both instances, the Dragon and PurpleDragon instances, because the PurpleDragon is a variant of the now scaled Dragon Prefab.