Prefab Variant
- Game Development course
- Intermediate
- Lesson 53/83
- 4 min
Learn to create customized derivatives with Prefab Variants.
What Is a Prefab Variant?
A Prefab Variant is a customized derivative created from an existing Prefab. It maintains a connection to the base Prefab but can contain its own changes. For example, you can create a faster or visually different Variant from a base enemy Prefab.
// Base Enemy Prefab
// Fast Enemy Variant
// Armored Enemy VariantOverrides and the Source Relationship
Changes made to a Prefab Variant can be stored as override values that differ from the base Prefab. When the base Prefab is updated, the Variant can receive source changes while preserving its own overrides. This structure makes shared properties easier to manage centrally.
// Base Prefab: Speed = 3
// Variant Override: Speed = 6Practice Use a Customized Value for a Variant
Declare a public variable representing movement speed for an enemy Prefab Variant. Set its initial value to 6 so it differs from the base Prefab. This value can be overridden for the Variant through the Inspector.
Starter code
using UnityEngine;
public class EnemyVariantSettings : MonoBehaviour
{
}Sample solution
using UnityEngine;
public class EnemyVariantSettings : MonoBehaviour
{
public float movementSpeed = 6f;
}Expected output
Variant hareket hızı: 6
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What is the main purpose of creating a Prefab Variant?
- Forcing the source Prefab to be deleted
- Turning all scene objects into a single object
- Moving the project to a different Unity version
- Creating a customized derivative while preserving the base Prefab structure Correct answer
Explanation: A Prefab Variant creates a modified version while preserving its connection to the base Prefab.
2 Prefab Derivative
Mevcut bir Prefab temel alınarak oluşturulan özelleştirilmiş sürüme Prefab ____ adı verilir.
Mevcut bir Prefab temel alınarak oluşturulan özelleştirilmiş sürüme Prefab Variant adı verilir.
Explanation: A Prefab Variant is a customized derivative created from a base Prefab.
3 Match the Variant Structure
| Term | Meaning |
|---|---|
Base Prefab |
Original source of the derivative |
Prefab Variant |
Customized version of the base source |
Override |
A change specific to the derivative |
Inheritance |
Inheriting properties from base source |