‫Hello and welcome.
‫In this lecture, we're going to be learning about setting location calling functions in C++ so that
‫we can bring a cube to a new location when we start playing.
‫As you can see here, this cube suddenly appeared when we started playing.
‫Let's dive in and see how functions work in C++.
‫So let's take a look at how functions translate from Blueprint over into C++, particularly using functions
‫at this stage.
‫We'll have a look at how to create our own later on in this section.
‫So to refresh your memory, this is what a function looks like in Blueprint.
‫You can see we have a node, we've got input pins on the left, output pins on the right, and we can
‫plug things like a variable into an input pin to do the same thing in C++.
‫Looks like this you use again function names have no spaces in them.
‫So instead of having a set actor location node as separate words, we have it all run together using
‫camel case and then we have our parentheses.
‫And inside the parentheses we have a list of inputs and these inputs could be more than one.
‫You can have them comma separated, but for the first instance we're going to just have one.
‫And these inputs are actually called arguments.
‫Don't ask me why I don't want to have an argument about it.
‫So we are going to have to put these variables in, but you don't have to pass variables.
‫Variables are just one way of doing it.
‫You can pass values as well.
‫So if we had a situation like this where we wanted just to set the location to 1 to 3, we can do that
‫in C++ as well by using the F Vector constructor directly inside the parentheses for the function.
‫So that means that we set it to a specific value rather than the value contained inside a variable.
‫So let's give that a go.
‫We'll go over to Visual Studio code and we're going to have a look at the Begin play just after we have
‫updated the My Vector.
‫I'm going to add a couple of new lines and I'm going to start typing set actor location, make sure
‫you type it correctly because names have to match exactly in C++, then you open your parentheses and
‫in here we are going to construct a new F vector value.
‫So we're going to type F vector open parentheses again.
‫And in here we are actually passing in arguments to the constructor for F Vector.
‫So this is very much like calling a function and then passing the value of that function into another
‫function.
‫But we'll talk more about that sort of stuff later on.
‫And what we can do here is type in one, comma two, comma three, and that means that the f vector
‫one, two, three is going to be passed into set actor location and then we can put a semicolon at the
‫end of the completed line.
‫So let's go into unreal.
‫Let's go ahead and compile the code.
‫And for us to be able to see the effect of this, we need to go to our moving platform actor and you'll
‫notice there are actually no components on this actor, which means that it can't actually have a position
‫because only components can give it a position.
‫So we can go ahead and add something like a cube to this moving platform actor or go to the ad in the
‫details pane and we go down to Cube and that gives us a cube and we can go ahead and hit play and see
‫whether we're able to set this act as location.
‫We can click on the moving platform and then we can eject using the eject button in the toolbar and
‫then double click on moving platform.
‫And you can see it takes us to the moving platform's location.
‫And with that selected in the outlier or in the scene view, we can have a look at the details pane
‫and we can see that.
‫Sure enough, the transform says that its location is one, two, three.
‫We've set that correctly in C++ code.
‫Now for this next part, it's going to be just confusing if we are setting the Y value of my vector
‫from the my x variable.
‫So let's delete that line and begin play for me.
‫That's line 19 and I'll delete a few of the extra empty lines there so that we've just got one between
‫the super big in play and set actor location.
‫Then I'd like to challenge you to use a variable instead of constructing the f vector in place.
‫So replace the F vector constructor that we're using.
‫Update the my vector so that it has a different location.
‫Can you bring it so that it is closer to the player?
‫When we hit play, the cube is actually positioned somewhere where the player can see it.
‫Pause the video and have a go.
‫Hello and welcome back.
‫So the way we do this is by removing this F vector and it's parentheses and it's arguments, and that's
‫what they're called, remember?
‫And then in as the argument to set actor location, we are going to type my vector.
‫So it's going to use the value inside the my vector variable to set the actor's location on begin play
‫when we begin playing.
‫So let's go into unreal let's stop play for now.
‫Let's have a look at the location of our third person character.
‫We can see that there is this is the location here.
‫What I can actually do, you could copy each of these manually.
‫You could actually just right click on the location, click copy, go over to your moving platform.
‫And where we have my vector, we can right click and hit paste and it's going to paste the entire vector
‫right in there.
‫So now we know that I'm moving Platform Cube is over here at 000.
‫But if I hit play, well, actually not very much happens because I forgot to compile.
‫This is the thing to always remember that we do need to compile any changes to C++.
‫So we must hit that compile button and only when that is complete will we actually see the changes that
‫we've made.
‫So let's go ahead and hit play.
‫And there you go.
‫We've got the cube standing right in front of our player.
‫So we've successfully moved it in begin play using C++ code.
‫Great stuff.
‫I'll see you in the next lecture.