In this lecture, we're going to go through just a really quick introduction to prefab variants.
So you can see that you can easily make different looks and feels and sizes and things of your game
objects, things that have been prefab in your game to create variation for your player.
We've learned that prefabs are a great way to create a template that we can use throughout our many
levels and scenes, and we can quickly make one change to one thing and one spot the prefab and then
it rolls out to all of the instances.
We can also make prefab variants, so let's have a look at that.
So I've got one coin prefab down in here.
If I was to take one of my other coins in the scene and get there and say, You know what, I'd like
to have a bigger coin.
So if I change the scale this to say 2 to 2 on my scaling, we've got a big coin and I can grab that
coin now and drag that down into my prefab area and create a prefab variant.
And that prefab variant will have links to the original prefab coin, so just rename it instead of being
a coin two.
I'll click on it once and rename it Big Coin, we'll say or mega coin, something like that.
And then we've got the original coin.
I'll just leave that as called coin.
It's a little bit of pain to have to go back and call everything original when you go and make some
variants.
So I'll just leave the original as original and you know, it's probably even sensible instead of just
big coins.
And I'm a big coin variant.
So that we're very clear that, oh, that thing is going to link to whatever the coin is.
Now, what does all this mean?
If I change something fundamental on our coin, on our parent prefab, if you will, then it will change
things on any of the variants that sit underneath that higher level object.
So in here, if I was to change the coin, we'll say, for example, the volume on our coin when we
on our audio source, this is on the main coin here.
If I was to drag that down, down, down to say 0.5, which I've kind of been wanting to do because
it's a little bit loud.
0.5 Now when I click on Bitcoin, you can see it has been changed as well.
It sounds like I'm saying Bitcoin, doesn't it?
I'm just saying Bitcoin calm down.
This is not a crypto course, but it could be.
It could be a little man's running around in our crypto world.
There's a theme for your game if you're looking for a theme.
So we've made a change in there.
What it won't change is if we go and change, say the scale or the position or the rotation of our parent
objects.
So if I change the scale here to something weird on the X, you'll see blink all of my other coins.
So these ones that are based on the original coin prefab they change.
But our coin variant doesn't change.
I'll just undo that.
However, if I change any of the other components at will.
So if I want to change my coins and give them a different color, so if I click on a bluey kind of thing,
then everything becomes green, even my variant.
So things that are further down the tree change as well.
I just put that back to normal.
However, if I go and change something on the variant, for example on the bitcoin, I go and change
that to say a green colour.
Then it won't propagate up the hierarchy to those other coins.
So it's a really handy way for us to make a base object.
So in other words, a base enemy or a base coin that has consistent properties that we know everything
needs to have movement and collision and all these kind of things, but then we can quickly create some
variation in that.
So it looks different and exciting to our player that the coins aren't always exactly the same.
I could also on my big coin here, I'm going to say it carefully now I'm just going to turn my big coin
back to yellow.
I think it's fine.
It looks different because it's big.
It doesn't need to be green as well.
I could also go and change on here the points per pick up, say for example, 300 on here.
Now if I go and drag another big coin into the world, if I click on that, it also has 300 points.
But these little coins, if I can click on one of the little coins, it's still only has 100 points
for pickup.
Now, if I go and change these points in here, if I go and change the number of points you get for
a small coin.
So back on to the small coin, main prefab.
If I was to change the number of points here to 200, for example, then you'll be able to see that
both of my little coins are now at 200.
If I can find that 200 and this one's at 200, however my prefab variants are going to remain at, if
I click on it, remain at 300.
And that's because I've gone and made a change to the variant.
So when it's different, the change to the parent is not going to override that.
Very similar the way normal prefabs work.
When you've changed an instance, there's some things that get propagated and some things that don't.
But because I've gone and said, You know what, these ones are 300.
Then if I go and change these to something else to 200 or 100 or 1000, it's not going to roll down
to the variant.
So that's just a little bit of an overview of what these things do in terms of how we can create variants,
variants.
So I've got a little bit of a challenge for you on here, and that is to mess around with variants,
experiment, and then to take one or more aspect of your game and create variants for them.
For example, there's something else in our scene at the moment that we can mess around with a little
bit that I'll be messing around with.
So pause the video and play around with prefab variants and get some variation in your game.
Okay.
As hinted at, I'm going to click on one of the Goobers if I can click on Goober there.
Okay.
We've got Goober Enemy and I'm going to drag that down into my prefab folder.
So I'll drag it first and then mess around on it second.
Yes, I want to create a prefab variant and then instead of Goober, we'll call this.
Let's see, red goober variant.
Side note I've got my icons like this so that you can see visually what I'm clicking on, but I often
have it like this so that I can see the name of things more fully and more easily.
But I'll pop it back to there so you can see.
But it just does mean that often my names are getting cut off on the screen here.
It's a little bit harder to see.
So I've got Red Goober.
Let's go and make the goober.
Let's see.
Red.
Good idea, Rick.
After calling him that, he kind of needs to live up to the name.
So this is a really imperfect way of changing the color on sprites in our game.
By the way, it's better if we go back to the original Photoshop file or the original PNG that we've
got and color it in there.
But this is just some quick and dirty way that I can show you some of these concepts in the game.
And if we'd set our enemies up so that they have health on them or they took a certain number of hits,
or maybe this one was invincible and that one wasn't.
There's plenty of other things we could do with the variant.
For now, it's just color, so it easily allows us to drag in some different colors into the world.
So let's just make sure everything works.
But we can still jump on those coins.
They behave as expected, the persistence behaves as expected.
And we've got different colored goober that if I so desired, I could get there and say, Let's put
in another red one or let's put in another original one, and we could make changes on the original
one that most of those changes are going to propagate down to the variant.
So there's just a little quick intro and overview of how prefab variants work.
It's a really powerful way if you get a lot of variation in your game for your player.
Okay, I'll see you in the next lecture.