1
00:00:03,080 --> 00:00:06,470
In this lecture, we're going to go through just a really quick introduction to prefab variants.

2
00:00:06,470 --> 00:00:11,480
So you can see that you can easily make different looks and feels and sizes and things of your game

3
00:00:11,480 --> 00:00:15,650
objects, things that have been prefab in your game to create variation for your player.

4
00:00:15,830 --> 00:00:19,790
We've learned that prefabs are a great way to create a template that we can use throughout our many

5
00:00:19,790 --> 00:00:25,130
levels and scenes, and we can quickly make one change to one thing and one spot the prefab and then

6
00:00:25,130 --> 00:00:27,020
it rolls out to all of the instances.

7
00:00:27,020 --> 00:00:29,870
We can also make prefab variants, so let's have a look at that.

8
00:00:29,870 --> 00:00:32,810
So I've got one coin prefab down in here.

9
00:00:32,840 --> 00:00:37,040
If I was to take one of my other coins in the scene and get there and say, You know what, I'd like

10
00:00:37,040 --> 00:00:38,570
to have a bigger coin.

11
00:00:38,570 --> 00:00:45,830
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

12
00:00:45,830 --> 00:00:52,040
coin now and drag that down into my prefab area and create a prefab variant.

13
00:00:52,040 --> 00:00:57,410
And that prefab variant will have links to the original prefab coin, so just rename it instead of being

14
00:00:57,410 --> 00:00:58,520
a coin two.

15
00:00:58,550 --> 00:01:04,340
I'll click on it once and rename it Big Coin, we'll say or mega coin, something like that.

16
00:01:04,340 --> 00:01:05,630
And then we've got the original coin.

17
00:01:05,630 --> 00:01:07,190
I'll just leave that as called coin.

18
00:01:07,190 --> 00:01:11,060
It's a little bit of pain to have to go back and call everything original when you go and make some

19
00:01:11,060 --> 00:01:11,510
variants.

20
00:01:11,510 --> 00:01:15,500
So I'll just leave the original as original and you know, it's probably even sensible instead of just

21
00:01:15,780 --> 00:01:16,310
big coins.

22
00:01:16,310 --> 00:01:18,740
And I'm a big coin variant.

23
00:01:20,220 --> 00:01:23,970
So that we're very clear that, oh, that thing is going to link to whatever the coin is.

24
00:01:23,970 --> 00:01:25,670
Now, what does all this mean?

25
00:01:25,680 --> 00:01:32,370
If I change something fundamental on our coin, on our parent prefab, if you will, then it will change

26
00:01:32,370 --> 00:01:36,990
things on any of the variants that sit underneath that higher level object.

27
00:01:36,990 --> 00:01:42,780
So in here, if I was to change the coin, we'll say, for example, the volume on our coin when we

28
00:01:42,780 --> 00:01:45,300
on our audio source, this is on the main coin here.

29
00:01:45,300 --> 00:01:49,560
If I was to drag that down, down, down to say 0.5, which I've kind of been wanting to do because

30
00:01:49,560 --> 00:01:50,520
it's a little bit loud.

31
00:01:50,520 --> 00:01:55,020
0.5 Now when I click on Bitcoin, you can see it has been changed as well.

32
00:01:55,020 --> 00:01:56,640
It sounds like I'm saying Bitcoin, doesn't it?

33
00:01:56,640 --> 00:01:58,410
I'm just saying Bitcoin calm down.

34
00:01:58,410 --> 00:02:00,420
This is not a crypto course, but it could be.

35
00:02:00,420 --> 00:02:03,320
It could be a little man's running around in our crypto world.

36
00:02:03,330 --> 00:02:05,580
There's a theme for your game if you're looking for a theme.

37
00:02:05,580 --> 00:02:07,110
So we've made a change in there.

38
00:02:07,110 --> 00:02:13,170
What it won't change is if we go and change, say the scale or the position or the rotation of our parent

39
00:02:13,170 --> 00:02:13,560
objects.

40
00:02:13,560 --> 00:02:18,960
So if I change the scale here to something weird on the X, you'll see blink all of my other coins.

41
00:02:18,960 --> 00:02:23,820
So these ones that are based on the original coin prefab they change.

42
00:02:23,820 --> 00:02:25,860
But our coin variant doesn't change.

43
00:02:25,860 --> 00:02:26,940
I'll just undo that.

44
00:02:26,940 --> 00:02:29,490
However, if I change any of the other components at will.

45
00:02:29,490 --> 00:02:34,350
So if I want to change my coins and give them a different color, so if I click on a bluey kind of thing,

46
00:02:34,350 --> 00:02:37,320
then everything becomes green, even my variant.

47
00:02:37,320 --> 00:02:39,960
So things that are further down the tree change as well.

48
00:02:39,960 --> 00:02:41,400
I just put that back to normal.

49
00:02:41,400 --> 00:02:46,740
However, if I go and change something on the variant, for example on the bitcoin, I go and change

50
00:02:46,740 --> 00:02:49,200
that to say a green colour.

51
00:02:49,230 --> 00:02:52,710
Then it won't propagate up the hierarchy to those other coins.

52
00:02:52,710 --> 00:02:55,260
So it's a really handy way for us to make a base object.

53
00:02:55,260 --> 00:03:00,510
So in other words, a base enemy or a base coin that has consistent properties that we know everything

54
00:03:00,510 --> 00:03:05,130
needs to have movement and collision and all these kind of things, but then we can quickly create some

55
00:03:05,130 --> 00:03:06,030
variation in that.

56
00:03:06,030 --> 00:03:10,290
So it looks different and exciting to our player that the coins aren't always exactly the same.

57
00:03:10,290 --> 00:03:15,000
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

58
00:03:15,000 --> 00:03:15,720
back to yellow.

59
00:03:15,720 --> 00:03:16,290
I think it's fine.

60
00:03:16,290 --> 00:03:17,850
It looks different because it's big.

61
00:03:17,850 --> 00:03:19,560
It doesn't need to be green as well.

62
00:03:19,560 --> 00:03:24,990
I could also go and change on here the points per pick up, say for example, 300 on here.

63
00:03:24,990 --> 00:03:31,710
Now if I go and drag another big coin into the world, if I click on that, it also has 300 points.

64
00:03:31,710 --> 00:03:37,200
But these little coins, if I can click on one of the little coins, it's still only has 100 points

65
00:03:37,200 --> 00:03:37,740
for pickup.

66
00:03:37,740 --> 00:03:42,210
Now, if I go and change these points in here, if I go and change the number of points you get for

67
00:03:42,210 --> 00:03:42,810
a small coin.

68
00:03:42,810 --> 00:03:45,870
So back on to the small coin, main prefab.

69
00:03:45,870 --> 00:03:50,640
If I was to change the number of points here to 200, for example, then you'll be able to see that

70
00:03:50,640 --> 00:03:54,600
both of my little coins are now at 200.

71
00:03:54,600 --> 00:04:02,370
If I can find that 200 and this one's at 200, however my prefab variants are going to remain at, if

72
00:04:02,370 --> 00:04:04,710
I click on it, remain at 300.

73
00:04:04,710 --> 00:04:07,470
And that's because I've gone and made a change to the variant.

74
00:04:07,470 --> 00:04:11,940
So when it's different, the change to the parent is not going to override that.

75
00:04:11,940 --> 00:04:14,370
Very similar the way normal prefabs work.

76
00:04:14,370 --> 00:04:18,420
When you've changed an instance, there's some things that get propagated and some things that don't.

77
00:04:18,420 --> 00:04:20,850
But because I've gone and said, You know what, these ones are 300.

78
00:04:20,850 --> 00:04:26,400
Then if I go and change these to something else to 200 or 100 or 1000, it's not going to roll down

79
00:04:26,400 --> 00:04:26,910
to the variant.

80
00:04:26,910 --> 00:04:31,290
So that's just a little bit of an overview of what these things do in terms of how we can create variants,

81
00:04:31,290 --> 00:04:31,740
variants.

82
00:04:31,740 --> 00:04:35,970
So I've got a little bit of a challenge for you on here, and that is to mess around with variants,

83
00:04:35,970 --> 00:04:40,110
experiment, and then to take one or more aspect of your game and create variants for them.

84
00:04:40,110 --> 00:04:43,740
For example, there's something else in our scene at the moment that we can mess around with a little

85
00:04:43,740 --> 00:04:45,030
bit that I'll be messing around with.

86
00:04:45,030 --> 00:04:49,860
So pause the video and play around with prefab variants and get some variation in your game.

87
00:04:52,440 --> 00:04:52,890
Okay.

88
00:04:52,920 --> 00:04:57,160
As hinted at, I'm going to click on one of the Goobers if I can click on Goober there.

89
00:04:57,180 --> 00:04:57,450
Okay.

90
00:04:57,450 --> 00:05:02,820
We've got Goober Enemy and I'm going to drag that down into my prefab folder.

91
00:05:02,820 --> 00:05:05,770
So I'll drag it first and then mess around on it second.

92
00:05:05,790 --> 00:05:09,990
Yes, I want to create a prefab variant and then instead of Goober, we'll call this.

93
00:05:09,990 --> 00:05:14,940
Let's see, red goober variant.

94
00:05:16,050 --> 00:05:21,360
Side note I've got my icons like this so that you can see visually what I'm clicking on, but I often

95
00:05:21,360 --> 00:05:26,100
have it like this so that I can see the name of things more fully and more easily.

96
00:05:26,100 --> 00:05:28,050
But I'll pop it back to there so you can see.

97
00:05:28,050 --> 00:05:31,050
But it just does mean that often my names are getting cut off on the screen here.

98
00:05:31,050 --> 00:05:32,130
It's a little bit harder to see.

99
00:05:32,130 --> 00:05:33,210
So I've got Red Goober.

100
00:05:33,210 --> 00:05:34,560
Let's go and make the goober.

101
00:05:34,860 --> 00:05:35,370
Let's see.

102
00:05:35,370 --> 00:05:35,700
Red.

103
00:05:35,730 --> 00:05:36,630
Good idea, Rick.

104
00:05:36,660 --> 00:05:38,880
After calling him that, he kind of needs to live up to the name.

105
00:05:38,880 --> 00:05:43,680
So this is a really imperfect way of changing the color on sprites in our game.

106
00:05:43,680 --> 00:05:48,960
By the way, it's better if we go back to the original Photoshop file or the original PNG that we've

107
00:05:48,960 --> 00:05:50,190
got and color it in there.

108
00:05:50,190 --> 00:05:54,360
But this is just some quick and dirty way that I can show you some of these concepts in the game.

109
00:05:54,570 --> 00:05:59,220
And if we'd set our enemies up so that they have health on them or they took a certain number of hits,

110
00:05:59,220 --> 00:06:01,490
or maybe this one was invincible and that one wasn't.

111
00:06:01,500 --> 00:06:03,570
There's plenty of other things we could do with the variant.

112
00:06:03,570 --> 00:06:07,710
For now, it's just color, so it easily allows us to drag in some different colors into the world.

113
00:06:07,710 --> 00:06:08,910
So let's just make sure everything works.

114
00:06:08,910 --> 00:06:10,350
But we can still jump on those coins.

115
00:06:10,350 --> 00:06:13,560
They behave as expected, the persistence behaves as expected.

116
00:06:13,560 --> 00:06:17,910
And we've got different colored goober that if I so desired, I could get there and say, Let's put

117
00:06:17,910 --> 00:06:22,740
in another red one or let's put in another original one, and we could make changes on the original

118
00:06:22,740 --> 00:06:26,100
one that most of those changes are going to propagate down to the variant.

119
00:06:26,100 --> 00:06:29,580
So there's just a little quick intro and overview of how prefab variants work.

120
00:06:29,580 --> 00:06:33,240
It's a really powerful way if you get a lot of variation in your game for your player.

121
00:06:33,270 --> 00:06:34,500
Okay, I'll see you in the next lecture.

