﻿1
00:00:04,370 --> 00:00:05,420
‫Hello and welcome.

2
00:00:05,420 --> 00:00:11,990
‫In this lecture, we're going to learn how to create classes that allow us to share configuration and

3
00:00:11,990 --> 00:00:16,520
‫functionality between multiple objects in our scene.

4
00:00:16,520 --> 00:00:18,410
‫Let's dive in and see how it works.

5
00:00:19,040 --> 00:00:27,460
‫Now the real power of programming with objects comes when we start to use classes and instances.

6
00:00:27,470 --> 00:00:29,150
‫Well, what is a class?

7
00:00:29,150 --> 00:00:36,680
‫Well, effectively it is a like a template or a blueprint in the regular sense of that word for objects.

8
00:00:36,680 --> 00:00:43,670
‫So this adventure here, we call this the adventurer class and it has some default data and it has some

9
00:00:43,670 --> 00:00:50,180
‫functionality, but we can go and create an instance of this class, such as adventure number one.

10
00:00:50,420 --> 00:00:57,860
‫We could call in Bob, for example, and he has his own copy of that data from the Adventurer class.

11
00:00:57,860 --> 00:01:03,410
‫This is the actual object and the class is something that we make the objects from.

12
00:01:03,830 --> 00:01:10,610
‫You can also then have an adventurer to a second instance of the same class and they share the functionality,

13
00:01:10,610 --> 00:01:15,470
‫notice they share all the same functionality and they can have their own version of the data.

14
00:01:15,470 --> 00:01:19,220
‫So you can see Adventurer two has changed his experience points.

15
00:01:19,460 --> 00:01:21,770
‫Now the benefit of this is twofold.

16
00:01:21,770 --> 00:01:27,710
‫One is that we're sharing all that functionality between these different objects, and second is that

17
00:01:27,710 --> 00:01:33,050
‫any of that data that we haven't changed such is the experience 500 or the level one.

18
00:01:33,050 --> 00:01:38,990
‫If I changed level one to level two, it would change it across all of the instances of the class as

19
00:01:38,990 --> 00:01:39,560
‫well.

20
00:01:39,800 --> 00:01:44,990
‫So how do we go and actually create something like this in Unreal?

21
00:01:45,410 --> 00:01:50,330
‫Well, the first thing I want to do is bring in something that's going to act as our projectile so the

22
00:01:50,330 --> 00:01:54,620
‫projectile can be our first object and class that we create.

23
00:01:54,950 --> 00:02:00,920
‫So I'm going to go to the quickly enter project button in the toolbar, go down to shapes and select

24
00:02:00,920 --> 00:02:03,650
‫sphere and drag a sphere into my scene.

25
00:02:03,650 --> 00:02:08,720
‫I'm also going to drag it up a little bit and I'm going to try and scale it, make it a little bit smaller

26
00:02:08,720 --> 00:02:10,160
‫by using the scale tool.

27
00:02:10,160 --> 00:02:16,610
‫And if I click here in the center on the White Bit, I can scale the whole thing uniformly till I've

28
00:02:16,610 --> 00:02:20,030
‫got something that's about the right size for my projectile.

29
00:02:20,330 --> 00:02:27,590
‫Now, what I want to do with this projectile is I want to turn it from just being a single object into

30
00:02:27,590 --> 00:02:31,970
‫being a blueprint class for multiple objects.

31
00:02:32,390 --> 00:02:34,280
‫There's an easy way that we can do this.

32
00:02:34,280 --> 00:02:38,270
‫Over in the details panel, there is a little blueprint button.

33
00:02:38,270 --> 00:02:43,370
‫If you click on that, you can see it says converts this actor into a reusable blueprint class that

34
00:02:43,370 --> 00:02:44,720
‫can have script behavior.

35
00:02:44,720 --> 00:02:49,970
‫So we can click on that and we just want to have this new subclass.

36
00:02:49,970 --> 00:02:51,590
‫We just leave the defaults as it is.

37
00:02:51,590 --> 00:02:54,500
‫The only thing we want to change is the name.

38
00:02:54,500 --> 00:03:00,950
‫Now what we want to call it is projectile, but there is a bit of a naming convention that we tend to

39
00:03:00,950 --> 00:03:01,130
‫use.

40
00:03:01,130 --> 00:03:02,150
‫It's not obligatory.

41
00:03:02,150 --> 00:03:09,290
‫It doesn't have any kind of functional impact on this project, but it does help us to understand things

42
00:03:09,290 --> 00:03:10,130
‫a little bit better.

43
00:03:10,130 --> 00:03:17,540
‫When we make a blueprint class, we tend to prefix it with BP in capital underscore, and that just

44
00:03:17,540 --> 00:03:20,060
‫allows us to instantly see what objects here are.

45
00:03:20,060 --> 00:03:21,290
‫Blueprint classes.

46
00:03:21,380 --> 00:03:28,610
‫We can go ahead and click select, which for some reason is effectively create and what it does, it

47
00:03:28,610 --> 00:03:34,940
‫goes ahead and opens up a new editor here, the editor for the Blueprint class itself.

48
00:03:34,940 --> 00:03:40,190
‫Now we can, like the other editors, dock this into the main window.

49
00:03:40,880 --> 00:03:43,040
‫And you can see again, we've got a lot of stuff.

50
00:03:43,040 --> 00:03:49,310
‫It's very similar to the level blueprint, but we've got a few other things such as a viewport in here

51
00:03:49,310 --> 00:03:57,020
‫that allows us to preview what this blueprint class would look like when we create an object instance

52
00:03:57,020 --> 00:03:57,740
‫of it.

53
00:03:58,130 --> 00:04:01,130
‫So now we've got this main class.

54
00:04:01,130 --> 00:04:07,010
‫We should be able to bring more instances and more objects of this class into the level.

55
00:04:07,370 --> 00:04:08,240
‫And indeed, we can.

56
00:04:08,240 --> 00:04:14,930
‫We could either duplicate the object that we've already got here, or you open up the content draw and

57
00:04:14,930 --> 00:04:17,210
‫right at the root of your content folder.

58
00:04:17,210 --> 00:04:22,640
‫If you select your content folder in the left hand pane, we've got a projectile blueprint.

59
00:04:22,640 --> 00:04:29,540
‫So what we can do is we can drag that into our scene and it will have created a new instance, a new

60
00:04:29,540 --> 00:04:31,610
‫copy of that blueprint.

61
00:04:31,610 --> 00:04:34,400
‫But like I said, these are linked copies.

62
00:04:34,400 --> 00:04:43,010
‫Making a change to a property in the BP projectile editor should change it for all instances.

63
00:04:43,010 --> 00:04:47,090
‫So the difference here is we've got a details pane over on the right.

64
00:04:47,090 --> 00:04:49,970
‫That's very much the same as the details pane we have in our level.

65
00:04:49,970 --> 00:04:56,630
‫Editor With the exception that you have to actually click on the components in the left hand pane to

66
00:04:56,630 --> 00:04:58,400
‫see their properties.

67
00:04:58,400 --> 00:05:03,680
‫So you may have to click down to static mesh components to see some of the properties we're used to

68
00:05:03,680 --> 00:05:06,620
‫seeing directly at the root actor level.

69
00:05:06,620 --> 00:05:11,960
‫So one thing to take note of how to do here is changing the material.

70
00:05:11,960 --> 00:05:16,520
‫So at the moment, this material on the ball is very white.

71
00:05:16,520 --> 00:05:18,440
‫We might want to change this to something.

72
00:05:18,910 --> 00:05:23,860
‫If you have this static mesh component selected over in the pane on the left and then go over to the

73
00:05:23,860 --> 00:05:29,110
‫details pane on the right, you can see that there's a section labeled Materials and Elements Zero.

74
00:05:29,140 --> 00:05:35,410
‫You can click the down arrow on this and you can see a list of all the materials we've got in our project,

75
00:05:35,410 --> 00:05:37,990
‫and you can select any of these and try them out.

76
00:05:37,990 --> 00:05:40,960
‫So I could try something like this cobblestone material.

77
00:05:40,960 --> 00:05:47,740
‫And you can see it looks a little bit ridiculous on our cannonball, so I am going to not use that one.

78
00:05:47,740 --> 00:05:53,150
‫So I'd like to challenge you to turn this projectile into a cannonball.

79
00:05:53,170 --> 00:05:56,350
‫Now, the way we're going to do this is, first of all, enabling physics.

80
00:05:56,350 --> 00:06:03,370
‫You will have to select the static mesh component to find the physics properties and then enable physics

81
00:06:03,370 --> 00:06:10,750
‫and choose a material of your liking that suits a cannonball a lot better than the current pebble one

82
00:06:10,750 --> 00:06:12,040
‫that I have selected.

83
00:06:12,040 --> 00:06:16,030
‫And then go back to your scene and have a look at what happens.

84
00:06:16,030 --> 00:06:18,530
‫What have they changed there or have they not?

85
00:06:18,550 --> 00:06:20,470
‫Pause, video and have a go.

86
00:06:24,060 --> 00:06:24,540
‫Okay.

87
00:06:24,540 --> 00:06:25,410
‫Welcome back.

88
00:06:25,440 --> 00:06:32,640
‫So, first of all, if I hit play, you'll notice that these two balls just sit there because physics

89
00:06:32,640 --> 00:06:33,390
‫isn't enabled.

90
00:06:33,390 --> 00:06:35,060
‫We're going to want physics enabled.

91
00:06:35,070 --> 00:06:40,650
‫So let's go to our details pane with the static mesh component selected over in the left hand pane.

92
00:06:40,650 --> 00:06:48,550
‫And we're going to scroll on down to where it has the physics section and checkbox for simulate physics.

93
00:06:48,570 --> 00:06:54,840
‫The other change I want to make here is I want to change the materials section and this is element zero.

94
00:06:54,870 --> 00:07:01,500
‫If you click on the dropdown now I'm going to look for a metallic one and I think I will go for the

95
00:07:01,500 --> 00:07:04,770
‫chrome metal material so I get a little chrome ball.

96
00:07:04,770 --> 00:07:05,940
‫Now, that's great.

97
00:07:05,940 --> 00:07:09,120
‫So it's not as boring looking as it was before.

98
00:07:09,690 --> 00:07:12,630
‫Now we can save if we want to, but it's not absolutely necessary.

99
00:07:12,630 --> 00:07:14,460
‫We can go ahead and hit play.

100
00:07:14,460 --> 00:07:19,020
‫And if we zoom out, you can see those balls are rolling around on the floor with physics enabled and

101
00:07:19,020 --> 00:07:25,920
‫with a new material, not just one of them, but both of them because they are linked back to this blueprint

102
00:07:25,920 --> 00:07:28,200
‫class and they are instances of it.

103
00:07:28,410 --> 00:07:29,400
‫So this is fantastic.

104
00:07:29,400 --> 00:07:36,930
‫We'll be able to use this for all sorts of things where we need multiple instances of the same class

105
00:07:36,930 --> 00:07:42,360
‫in our game and prevents us from having to repeat ourselves too many times.

106
00:07:42,360 --> 00:07:43,080
‫Great stuff.

107
00:07:43,080 --> 00:07:44,640
‫I'll see you in the next lecture.

