Lecture 15: Prefab Variants
Introduction
In this lecture, we'll explore prefab variants, a powerful Unity feature that allows for creating variations of a prefab without modifying the original asset. This functionality is invaluable when you need to reuse a prefab but with different properties, such as materials, textures, or components.
What Are Prefab Variants?
Prefab variants derive from a base prefab and inherit all its properties and components. You can alter these variants without affecting the base prefab, facilitating the creation of multiple instances each with unique characteristics.
Creating a Prefab Variant
This lecture will focus on creating prefab variants for world scenes, player characters, and pet characters.
- Create a new folder in your project directory specifically for storing the prefab variants.
- Right-click in the project window, select
Create > Highrise > Scene Variant
to create a world scene variant. Repeat this process to create a "World Variant". - Choose "Use this Prefab" to designate the prefab as the base for your variant.
- Navigate to
PlayerCharacterSpawner
and find thePlayerCharacter
prefab. - Drag the
PlayerCharacter
prefab into the newly created folder to generate a player character variant. Perform the same action for thePetCharacter
. - Place both the player character and pet character variants into the world scene variant to assemble a complete scene.
- Adjust the properties of the variants as necessary, such as changing scale, adding or modifying components, adjusting speed, or other attributes.
Change Character Scale and Speed
- Select the player character variant in the hierarchy.
- In the inspector, find the
Character (Script)
component. - Adjust the speed to your preferred setting.
- Modify the scale within the
Transform
component to resize the character. - Repeat these steps for the pet character variant.
YouTube Tutorial
Conclusion
Prefab variants are a potent tool in Unity, enabling the creation of prefab variations without impacting the original asset. Utilizing prefab variants can significantly streamline customization and reuse of prefabs in your projects, enhancing both efficiency and productivity in development.
Updated about 1 month ago