What could you use prefab variants for?

I’m interested in knowing what variants you will introduce in your game?

Might become a source of pain, not sure I’ll use them.
For example like in this lesson (36), I create the variant for the Player, remove the PlayerController component from the base Character prefab, and add it to the Player variant.
So far so good. But then since the PlayerController was pasted at the bottom of the inspector, I decide to reorganize a bit and move the component up… and it’s not possible. Cannot move components in child, most go to parent. But the parent does not have the PlayerController component anymore :crazy_face:

It’s a small price to pay for how much time they can save.

So far, I am not attracted to the idea of using prefab variants. I prefer to use an abstract base class.
My architecture so far is Actor > Fighter | Actor > NPC | Actor > Wizard. In Actor I have several enums which decide faction, alignment, race. I also do the same for Weapon and Armor, which also have enums that decide “Type”. Is there a benefit for using prefab variants vs abstraction?

These are not necessarily mutually exclusive things… We often have prefabs that are virtually identical… for example in the RPG course, we use a Pickup prefab to represent an item on the ground still waiting to be picked up… At the root level, the prefab needs a collider, a Pickup script with a link to the item’s scriptable object, and under the root, we usually put the actual mesh for the item.

So I might have a base pickup class that has all the boilerplate stuff set up, and just needs the link to the scriptable object and the mesh changed…
Then I can make a pickup with a regular sword for the regular boring sword, say for a character like Cameron to wield, and another pickup with stave suitable for a powerful red robed mage like Raistlin… Each of these pickups are Prefab variants.
Now here is where the real advantage of variants shows up… suppose you decide after you’ve made 100 prefabs that you want pickups to have a particle system to highlight to the player that the item is on the ground… all you have to do is add that particle system to the base prefab and it automatically appears in all those prefab variants. Very similar to how we use abstract classes and inherit properties this same feature applies to prefabs.

1 Like