‫Hello and welcome.
‫In this lecture, we're going to learn how to create classes that allow us to share configuration and
‫functionality between multiple objects in our scene.
‫Let's dive in and see how it works.
‫Now the real power of programming with objects comes when we start to use classes and instances.
‫Well, what is a class?
‫Well, effectively it is a like a template or a blueprint in the regular sense of that word for objects.
‫So this adventure here, we call this the adventurer class and it has some default data and it has some
‫functionality, but we can go and create an instance of this class, such as adventure number one.
‫We could call in Bob, for example, and he has his own copy of that data from the Adventurer class.
‫This is the actual object and the class is something that we make the objects from.
‫You can also then have an adventurer to a second instance of the same class and they share the functionality,
‫notice they share all the same functionality and they can have their own version of the data.
‫So you can see Adventurer two has changed his experience points.
‫Now the benefit of this is twofold.
‫One is that we're sharing all that functionality between these different objects, and second is that
‫any of that data that we haven't changed such is the experience 500 or the level one.
‫If I changed level one to level two, it would change it across all of the instances of the class as
‫well.
‫So how do we go and actually create something like this in Unreal?
‫Well, the first thing I want to do is bring in something that's going to act as our projectile so the
‫projectile can be our first object and class that we create.
‫So I'm going to go to the quickly enter project button in the toolbar, go down to shapes and select
‫sphere and drag a sphere into my scene.
‫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
‫by using the scale tool.
‫And if I click here in the center on the White Bit, I can scale the whole thing uniformly till I've
‫got something that's about the right size for my projectile.
‫Now, what I want to do with this projectile is I want to turn it from just being a single object into
‫being a blueprint class for multiple objects.
‫There's an easy way that we can do this.
‫Over in the details panel, there is a little blueprint button.
‫If you click on that, you can see it says converts this actor into a reusable blueprint class that
‫can have script behavior.
‫So we can click on that and we just want to have this new subclass.
‫We just leave the defaults as it is.
‫The only thing we want to change is the name.
‫Now what we want to call it is projectile, but there is a bit of a naming convention that we tend to
‫use.
‫It's not obligatory.
‫It doesn't have any kind of functional impact on this project, but it does help us to understand things
‫a little bit better.
‫When we make a blueprint class, we tend to prefix it with BP in capital underscore, and that just
‫allows us to instantly see what objects here are.
‫Blueprint classes.
‫We can go ahead and click select, which for some reason is effectively create and what it does, it
‫goes ahead and opens up a new editor here, the editor for the Blueprint class itself.
‫Now we can, like the other editors, dock this into the main window.
‫And you can see again, we've got a lot of stuff.
‫It's very similar to the level blueprint, but we've got a few other things such as a viewport in here
‫that allows us to preview what this blueprint class would look like when we create an object instance
‫of it.
‫So now we've got this main class.
‫We should be able to bring more instances and more objects of this class into the level.
‫And indeed, we can.
‫We could either duplicate the object that we've already got here, or you open up the content draw and
‫right at the root of your content folder.
‫If you select your content folder in the left hand pane, we've got a projectile blueprint.
‫So what we can do is we can drag that into our scene and it will have created a new instance, a new
‫copy of that blueprint.
‫But like I said, these are linked copies.
‫Making a change to a property in the BP projectile editor should change it for all instances.
‫So the difference here is we've got a details pane over on the right.
‫That's very much the same as the details pane we have in our level.
‫Editor With the exception that you have to actually click on the components in the left hand pane to
‫see their properties.
‫So you may have to click down to static mesh components to see some of the properties we're used to
‫seeing directly at the root actor level.
‫So one thing to take note of how to do here is changing the material.
‫So at the moment, this material on the ball is very white.
‫We might want to change this to something.
‫If you have this static mesh component selected over in the pane on the left and then go over to the
‫details pane on the right, you can see that there's a section labeled Materials and Elements Zero.
‫You can click the down arrow on this and you can see a list of all the materials we've got in our project,
‫and you can select any of these and try them out.
‫So I could try something like this cobblestone material.
‫And you can see it looks a little bit ridiculous on our cannonball, so I am going to not use that one.
‫So I'd like to challenge you to turn this projectile into a cannonball.
‫Now, the way we're going to do this is, first of all, enabling physics.
‫You will have to select the static mesh component to find the physics properties and then enable physics
‫and choose a material of your liking that suits a cannonball a lot better than the current pebble one
‫that I have selected.
‫And then go back to your scene and have a look at what happens.
‫What have they changed there or have they not?
‫Pause, video and have a go.
‫Okay.
‫Welcome back.
‫So, first of all, if I hit play, you'll notice that these two balls just sit there because physics
‫isn't enabled.
‫We're going to want physics enabled.
‫So let's go to our details pane with the static mesh component selected over in the left hand pane.
‫And we're going to scroll on down to where it has the physics section and checkbox for simulate physics.
‫The other change I want to make here is I want to change the materials section and this is element zero.
‫If you click on the dropdown now I'm going to look for a metallic one and I think I will go for the
‫chrome metal material so I get a little chrome ball.
‫Now, that's great.
‫So it's not as boring looking as it was before.
‫Now we can save if we want to, but it's not absolutely necessary.
‫We can go ahead and hit play.
‫And if we zoom out, you can see those balls are rolling around on the floor with physics enabled and
‫with a new material, not just one of them, but both of them because they are linked back to this blueprint
‫class and they are instances of it.
‫So this is fantastic.
‫We'll be able to use this for all sorts of things where we need multiple instances of the same class
‫in our game and prevents us from having to repeat ourselves too many times.
‫Great stuff.
‫I'll see you in the next lecture.