‫Hello and welcome.
‫In this lecture, we're going to learn about objects and how we can use functionality on objects and
‫their data to start creating interesting programs.
‫Let's dive in.
‫So let's start off this lecture by introducing a new concept, the concept of objects.
‫It's absolutely vital to a lot of programming languages.
‫So an object is essentially a something that you want to represent a thing, something like in a game
‫you might have an adventurer.
‫He is an object in your world and he might have some data that represents what he is, things like he
‫is, experience points, for example, or maybe his level he's a level two adventurer.
‫Things like that are the data that make up an adventurer, but that's not all an adventurer is.
‫An adventurer is also some functionality, such as the ability to fire arrows, such as being able to
‫jump and so on.
‫There are other things that can be objects.
‫So for example, we can represent things in the real world, in the computer, such as the player,
‫and we could store relevant properties to the player things like is the player using a controller,
‫is the player number one or number two?
‫Those kinds of pieces of data and the relevant functionality such as get their current input.
‫Are they holding down the space bar, for example, get the skill level of the player and then you can
‫have completely abstract objects, things like a list.
‫So you could have a list that has the items one, two, three, four in it, or maybe it could have
‫any items that you like in it.
‫The data could change, but it might also have some functionality, such as remove the last item from
‫the list or add to the end of the list.
‫So you can see objects are very, very flexible.
‫They can be used to represent myriad different things.
‫And you'll notice that the functionality at the bottom of these objects is actually what those nodes
‫are or what a lot of nodes are in Blueprint.
‫So they start to get a little bit of a mapping between the objects and the functionality.
‫Okay.
‫So we've introduced a bunch of new concepts there.
‫Let's, let's just recap slightly.
‫So we've said that objects are collections of data and functionality.
‫What we may have not realized is that actors are actually objects.
‫Actors are objects that can go in a level.
‫And you can see this if you go into your level, you select the cube, you can see that there's a whole
‫bunch of in the details pane, a load of data.
‫And as we will see in a bit, there's a load of functionality in the node form in blueprint as well.
‫Then there are components.
‫Now components we haven't got into detail before, but here they are.
‫They are objects that can go on an actor, whereas actors go on the level, components go on an actor
‫itself.
‫So with the Cube selected, you can see at the top of the details pane that there is this static mesh
‫component.
‫If you actually click on that, you will see that the details pane gets a restricted set of details.
‫It shows you not all of the properties that are available on the Cube actor, but only the subset of
‫properties that belong to the static mesh component, which is basically the component responsible for
‫telling us how to draw a cube.
‫Now, these objects can often have a lot more data than this, and that means that they can become quite
‫heavy to manipulate by your computer and certainly if it has to copy these objects around.
‫So instead of doing that, we use a clever structure called a reference which is essentially just an
‫address or where do I go to find this object in the computer's memory so that I don't have to be moving
‫the object around all the time?
‫We'll cover a little bit more about how this actually works in memory when we get to C++, but for now,
‫it's enough to know that it's just an address.
‫So what we can do, for example, let's dive in to Unreal.
‫If we were in our main level and we wanted to use some functionality on our cube, then what I can do
‫is I can select the cube in the scene and then I can go over to my level blueprint and right click,
‫and then I can click a create reference to Cube and this creates a new node.
‫Now what's that doing?
‫Well, that's basically telling us this is the Cube's address.
‫If you want to do something with the cube, here's where you find it.
‫What happens in Blueprint when you run the game is it's going to go and find that cube.
‫And then you can ask questions or use functionality on the cube, such as saying, Hey, where does
‫your static mesh component live?
‫And he goes, okay, the static mesh components over there.
‫So we go and find the static mesh component and then we can ask questions of that and it can say, Hey,
‫what's your name?
‫Static mesh component.
‫And the static mesh component can say, Hey, my name is Bob.
‫And so that is how we can use these references and used functionality of multiple different objects
‫to get to where we want to go.
‫Now we've said that a reference is where to find an object, and now something else that's worth pointing
‫out is a data pin.
‫What is a.
‫Pinn Well, this cube reference actually has one.
‫This little blue round thing on its right hand side is a data pin.
‫We've actually seen these before on the print string nodes there on the left hand side, and they're
‫purple.
‫And how do these how are these different to the other types of pins that we've seen, these white pins?
‫Well, the data pin is the input or output of data for a node.
‫So a node, if it's on the left hand side, it's the input, it's the data that node can work with.
‫If it's on the right hand side side, it's the data that Node produces.
‫So in the case of the cube, this node produces a reference to the cube actor, then the execution pins.
‫These are actually what those white pins are really called to differentiate them from the data pins,
‫and they are still when to run the node.
‫So data pins are what to run the node with.
‫Execution pins are when to run it.
‫So with all that information, let's do a little bit of using the functionality of these objects.
‫So we've got our cube reference.
‫If we drag off of the cube reference pin, you can use all of the functionality that that cube has.
‫As I said, we've got a component on the cube called a static mesh component, and I want to go ahead
‫and get hold of a reference to that.
‫So we'll look for get static mesh component and the bottom most item for me is get static mesh component.
‫I can click on that.
‫We get a new node with the input being a cube reference and the output being a reference to its static
‫mesh component.
‫So if we drag off of that, then we can ask for the functionality of the static mesh components such
‫as get display name and that gets us the input of the static mesh component reference and it uses its
‫functionality of get display name and then it returns a string or a text value that we can print using
‫the print string node.
‫So we can drag off of that and type print string and then we can hook up the execution nodes so that
‫that runs after the other two print strings at begin play.
‫You'll notice that some of these nodes don't have execution pins.
‫That might be confusing.
‫When do they get run?
‫Well, they get run whenever the blueprints thinks it's appropriate, essentially whenever it's needed
‫by a node that does have an execution pin.
‫So if we go ahead and hit play, you can see that it pops up with a name cube static mesh component
‫zero or something like that.
‫It's a bit programming tree.
‫It's not, it's not Bob It's a bit more involved than that.
‫But you can see we've essentially coded in that chain of questions that I had on my slide.
‫So I'd like to challenge you to go ahead and get the mass of our static mesh component.
‫We have configured it in the past.
‫If you go into the level and have a look at the details pane, you can see that one of the physics property
‫was the mass and we've configured that as a piece of data on the static mesh component.
‫Well, if you delete the get display name node and drag off the static mesh component, you should be
‫able to search for get mass and that should get you the piece of data on the static mesh component and
‫see if you can print that value using our print string node pause video and have a go.
‫Okay.
‫Welcome back.
‫So if we go back to the blueprint, just delete our display name, drag off the static mesh component
‫and search for get mass.
‫Then we can pull in that node.
‫We've got a return value here and that's going to be our mass value.
‫You can see if you hover over it, it says returns the mass of this component in kilograms.
‫And by the way, return value just means the output data.
‫And then we can drag that node into our in string for the print string.
‫And you see it creates a little conversion node that's okay.
‫It's converting from whatever this value is into something that the print string will accept.
‫We can go ahead and hit play and you see we get the value of 1000, which we know was the mass we configured
‫or whatever you actually do configure.
‫You can change that and see that this value will change as well.
‫So that's it for this lecture.
‫We've learned about objects and their references and how to use functionality nodes in blueprint.