﻿1
00:00:04,830 --> 00:00:05,820
‫Hello and welcome.

2
00:00:05,820 --> 00:00:12,150
‫In this lecture, we're going to learn about objects and how we can use functionality on objects and

3
00:00:12,150 --> 00:00:16,170
‫their data to start creating interesting programs.

4
00:00:16,170 --> 00:00:17,700
‫Let's dive in.

5
00:00:18,910 --> 00:00:24,430
‫So let's start off this lecture by introducing a new concept, the concept of objects.

6
00:00:24,430 --> 00:00:27,670
‫It's absolutely vital to a lot of programming languages.

7
00:00:27,940 --> 00:00:35,560
‫So an object is essentially a something that you want to represent a thing, something like in a game

8
00:00:35,560 --> 00:00:37,120
‫you might have an adventurer.

9
00:00:37,120 --> 00:00:46,600
‫He is an object in your world and he might have some data that represents what he is, things like he

10
00:00:46,600 --> 00:00:51,490
‫is, experience points, for example, or maybe his level he's a level two adventurer.

11
00:00:51,490 --> 00:00:57,520
‫Things like that are the data that make up an adventurer, but that's not all an adventurer is.

12
00:00:57,520 --> 00:01:05,050
‫An adventurer is also some functionality, such as the ability to fire arrows, such as being able to

13
00:01:05,050 --> 00:01:06,670
‫jump and so on.

14
00:01:07,210 --> 00:01:09,130
‫There are other things that can be objects.

15
00:01:09,130 --> 00:01:15,310
‫So for example, we can represent things in the real world, in the computer, such as the player,

16
00:01:15,310 --> 00:01:21,040
‫and we could store relevant properties to the player things like is the player using a controller,

17
00:01:21,400 --> 00:01:23,980
‫is the player number one or number two?

18
00:01:24,010 --> 00:01:29,680
‫Those kinds of pieces of data and the relevant functionality such as get their current input.

19
00:01:29,890 --> 00:01:35,380
‫Are they holding down the space bar, for example, get the skill level of the player and then you can

20
00:01:35,380 --> 00:01:38,650
‫have completely abstract objects, things like a list.

21
00:01:38,650 --> 00:01:43,210
‫So you could have a list that has the items one, two, three, four in it, or maybe it could have

22
00:01:43,210 --> 00:01:44,470
‫any items that you like in it.

23
00:01:44,470 --> 00:01:50,590
‫The data could change, but it might also have some functionality, such as remove the last item from

24
00:01:50,590 --> 00:01:52,630
‫the list or add to the end of the list.

25
00:01:52,630 --> 00:01:55,180
‫So you can see objects are very, very flexible.

26
00:01:55,180 --> 00:01:58,660
‫They can be used to represent myriad different things.

27
00:01:58,660 --> 00:02:05,260
‫And you'll notice that the functionality at the bottom of these objects is actually what those nodes

28
00:02:05,260 --> 00:02:08,410
‫are or what a lot of nodes are in Blueprint.

29
00:02:08,410 --> 00:02:15,100
‫So they start to get a little bit of a mapping between the objects and the functionality.

30
00:02:15,490 --> 00:02:15,760
‫Okay.

31
00:02:15,760 --> 00:02:17,950
‫So we've introduced a bunch of new concepts there.

32
00:02:17,950 --> 00:02:19,810
‫Let's, let's just recap slightly.

33
00:02:19,810 --> 00:02:24,550
‫So we've said that objects are collections of data and functionality.

34
00:02:24,940 --> 00:02:28,930
‫What we may have not realized is that actors are actually objects.

35
00:02:28,930 --> 00:02:31,930
‫Actors are objects that can go in a level.

36
00:02:31,930 --> 00:02:36,790
‫And you can see this if you go into your level, you select the cube, you can see that there's a whole

37
00:02:36,790 --> 00:02:39,820
‫bunch of in the details pane, a load of data.

38
00:02:39,820 --> 00:02:45,370
‫And as we will see in a bit, there's a load of functionality in the node form in blueprint as well.

39
00:02:46,090 --> 00:02:47,380
‫Then there are components.

40
00:02:47,380 --> 00:02:50,800
‫Now components we haven't got into detail before, but here they are.

41
00:02:51,070 --> 00:02:57,040
‫They are objects that can go on an actor, whereas actors go on the level, components go on an actor

42
00:02:57,040 --> 00:02:57,610
‫itself.

43
00:02:57,610 --> 00:03:03,250
‫So with the Cube selected, you can see at the top of the details pane that there is this static mesh

44
00:03:03,250 --> 00:03:04,180
‫component.

45
00:03:04,540 --> 00:03:11,080
‫If you actually click on that, you will see that the details pane gets a restricted set of details.

46
00:03:11,080 --> 00:03:19,240
‫It shows you not all of the properties that are available on the Cube actor, but only the subset of

47
00:03:19,240 --> 00:03:25,840
‫properties that belong to the static mesh component, which is basically the component responsible for

48
00:03:25,840 --> 00:03:28,090
‫telling us how to draw a cube.

49
00:03:28,360 --> 00:03:34,330
‫Now, these objects can often have a lot more data than this, and that means that they can become quite

50
00:03:34,330 --> 00:03:40,600
‫heavy to manipulate by your computer and certainly if it has to copy these objects around.

51
00:03:40,720 --> 00:03:47,080
‫So instead of doing that, we use a clever structure called a reference which is essentially just an

52
00:03:47,080 --> 00:03:53,860
‫address or where do I go to find this object in the computer's memory so that I don't have to be moving

53
00:03:53,860 --> 00:03:55,690
‫the object around all the time?

54
00:03:55,690 --> 00:04:01,810
‫We'll cover a little bit more about how this actually works in memory when we get to C++, but for now,

55
00:04:01,810 --> 00:04:04,150
‫it's enough to know that it's just an address.

56
00:04:04,720 --> 00:04:09,730
‫So what we can do, for example, let's dive in to Unreal.

57
00:04:09,730 --> 00:04:17,110
‫If we were in our main level and we wanted to use some functionality on our cube, then what I can do

58
00:04:17,110 --> 00:04:22,300
‫is I can select the cube in the scene and then I can go over to my level blueprint and right click,

59
00:04:22,300 --> 00:04:27,790
‫and then I can click a create reference to Cube and this creates a new node.

60
00:04:27,850 --> 00:04:29,230
‫Now what's that doing?

61
00:04:29,230 --> 00:04:33,010
‫Well, that's basically telling us this is the Cube's address.

62
00:04:33,010 --> 00:04:35,980
‫If you want to do something with the cube, here's where you find it.

63
00:04:36,220 --> 00:04:41,260
‫What happens in Blueprint when you run the game is it's going to go and find that cube.

64
00:04:41,260 --> 00:04:47,110
‫And then you can ask questions or use functionality on the cube, such as saying, Hey, where does

65
00:04:47,110 --> 00:04:48,760
‫your static mesh component live?

66
00:04:48,760 --> 00:04:51,280
‫And he goes, okay, the static mesh components over there.

67
00:04:51,280 --> 00:04:56,530
‫So we go and find the static mesh component and then we can ask questions of that and it can say, Hey,

68
00:04:56,530 --> 00:04:57,370
‫what's your name?

69
00:04:57,370 --> 00:04:58,600
‫Static mesh component.

70
00:04:58,600 --> 00:05:01,540
‫And the static mesh component can say, Hey, my name is Bob.

71
00:05:01,540 --> 00:05:07,720
‫And so that is how we can use these references and used functionality of multiple different objects

72
00:05:07,720 --> 00:05:09,610
‫to get to where we want to go.

73
00:05:09,610 --> 00:05:16,000
‫Now we've said that a reference is where to find an object, and now something else that's worth pointing

74
00:05:16,000 --> 00:05:17,770
‫out is a data pin.

75
00:05:17,770 --> 00:05:18,250
‫What is a.

76
00:05:18,590 --> 00:05:21,320
‫Pinn Well, this cube reference actually has one.

77
00:05:21,320 --> 00:05:26,650
‫This little blue round thing on its right hand side is a data pin.

78
00:05:26,660 --> 00:05:30,530
‫We've actually seen these before on the print string nodes there on the left hand side, and they're

79
00:05:30,530 --> 00:05:31,220
‫purple.

80
00:05:31,370 --> 00:05:37,430
‫And how do these how are these different to the other types of pins that we've seen, these white pins?

81
00:05:37,580 --> 00:05:42,680
‫Well, the data pin is the input or output of data for a node.

82
00:05:42,680 --> 00:05:47,840
‫So a node, if it's on the left hand side, it's the input, it's the data that node can work with.

83
00:05:47,870 --> 00:05:52,100
‫If it's on the right hand side side, it's the data that Node produces.

84
00:05:52,100 --> 00:06:00,650
‫So in the case of the cube, this node produces a reference to the cube actor, then the execution pins.

85
00:06:00,650 --> 00:06:06,530
‫These are actually what those white pins are really called to differentiate them from the data pins,

86
00:06:06,530 --> 00:06:09,710
‫and they are still when to run the node.

87
00:06:09,710 --> 00:06:12,440
‫So data pins are what to run the node with.

88
00:06:12,440 --> 00:06:14,840
‫Execution pins are when to run it.

89
00:06:14,840 --> 00:06:21,470
‫So with all that information, let's do a little bit of using the functionality of these objects.

90
00:06:21,470 --> 00:06:23,360
‫So we've got our cube reference.

91
00:06:23,360 --> 00:06:30,290
‫If we drag off of the cube reference pin, you can use all of the functionality that that cube has.

92
00:06:30,290 --> 00:06:36,290
‫As I said, we've got a component on the cube called a static mesh component, and I want to go ahead

93
00:06:36,290 --> 00:06:38,390
‫and get hold of a reference to that.

94
00:06:38,390 --> 00:06:47,030
‫So we'll look for get static mesh component and the bottom most item for me is get static mesh component.

95
00:06:47,030 --> 00:06:48,050
‫I can click on that.

96
00:06:48,050 --> 00:06:55,460
‫We get a new node with the input being a cube reference and the output being a reference to its static

97
00:06:55,460 --> 00:06:56,480
‫mesh component.

98
00:06:56,480 --> 00:07:01,700
‫So if we drag off of that, then we can ask for the functionality of the static mesh components such

99
00:07:01,700 --> 00:07:11,330
‫as get display name and that gets us the input of the static mesh component reference and it uses its

100
00:07:11,330 --> 00:07:19,460
‫functionality of get display name and then it returns a string or a text value that we can print using

101
00:07:19,460 --> 00:07:20,330
‫the print string node.

102
00:07:20,330 --> 00:07:26,270
‫So we can drag off of that and type print string and then we can hook up the execution nodes so that

103
00:07:26,270 --> 00:07:30,680
‫that runs after the other two print strings at begin play.

104
00:07:31,010 --> 00:07:33,710
‫You'll notice that some of these nodes don't have execution pins.

105
00:07:33,710 --> 00:07:34,730
‫That might be confusing.

106
00:07:34,730 --> 00:07:35,870
‫When do they get run?

107
00:07:35,870 --> 00:07:42,500
‫Well, they get run whenever the blueprints thinks it's appropriate, essentially whenever it's needed

108
00:07:42,500 --> 00:07:45,050
‫by a node that does have an execution pin.

109
00:07:45,050 --> 00:07:50,090
‫So if we go ahead and hit play, you can see that it pops up with a name cube static mesh component

110
00:07:50,090 --> 00:07:51,170
‫zero or something like that.

111
00:07:51,170 --> 00:07:52,400
‫It's a bit programming tree.

112
00:07:52,430 --> 00:07:56,210
‫It's not, it's not Bob It's a bit more involved than that.

113
00:07:56,210 --> 00:08:02,240
‫But you can see we've essentially coded in that chain of questions that I had on my slide.

114
00:08:02,390 --> 00:08:09,200
‫So I'd like to challenge you to go ahead and get the mass of our static mesh component.

115
00:08:09,200 --> 00:08:11,270
‫We have configured it in the past.

116
00:08:11,270 --> 00:08:15,950
‫If you go into the level and have a look at the details pane, you can see that one of the physics property

117
00:08:15,950 --> 00:08:20,540
‫was the mass and we've configured that as a piece of data on the static mesh component.

118
00:08:20,660 --> 00:08:26,540
‫Well, if you delete the get display name node and drag off the static mesh component, you should be

119
00:08:26,540 --> 00:08:33,470
‫able to search for get mass and that should get you the piece of data on the static mesh component and

120
00:08:33,470 --> 00:08:39,920
‫see if you can print that value using our print string node pause video and have a go.

121
00:08:43,330 --> 00:08:43,930
‫Okay.

122
00:08:43,930 --> 00:08:44,800
‫Welcome back.

123
00:08:44,830 --> 00:08:51,640
‫So if we go back to the blueprint, just delete our display name, drag off the static mesh component

124
00:08:51,640 --> 00:08:53,680
‫and search for get mass.

125
00:08:53,890 --> 00:08:55,990
‫Then we can pull in that node.

126
00:08:55,990 --> 00:09:00,640
‫We've got a return value here and that's going to be our mass value.

127
00:09:00,640 --> 00:09:05,350
‫You can see if you hover over it, it says returns the mass of this component in kilograms.

128
00:09:05,350 --> 00:09:08,470
‫And by the way, return value just means the output data.

129
00:09:08,530 --> 00:09:14,590
‫And then we can drag that node into our in string for the print string.

130
00:09:14,590 --> 00:09:17,800
‫And you see it creates a little conversion node that's okay.

131
00:09:17,800 --> 00:09:22,900
‫It's converting from whatever this value is into something that the print string will accept.

132
00:09:22,900 --> 00:09:29,050
‫We can go ahead and hit play and you see we get the value of 1000, which we know was the mass we configured

133
00:09:29,050 --> 00:09:30,970
‫or whatever you actually do configure.

134
00:09:30,970 --> 00:09:34,810
‫You can change that and see that this value will change as well.

135
00:09:34,810 --> 00:09:36,220
‫So that's it for this lecture.

136
00:09:36,220 --> 00:09:43,090
‫We've learned about objects and their references and how to use functionality nodes in blueprint.

