‫Hello and welcome.
‫In this lecture, we're going to be learning about how we can access what is on the other side of a
‫pointer so that our mover component can get properties from the actor that it lives on, such as getting
‫the name of the actor or getting its location.
‫Let's dive in and see how we can do this.
‫So it's all very well to be able to get a pointer or get an address of an actor.
‫But we do need to be able to actually do stuff with the actor itself.
‫And the process for doing this is a little bit tricky to understand if we just looking at the actor.
‫So we're going to have a look at doing some pointers to floats just here within that tick component.
‫So let's start off by creating a float, which we're going to call my float and set this to a value
‫of five.
‫Then we're going to create a float pointer, which I'm going to call your float, and we're going to
‫set that to be the address of the my float.
‫So these are both pointing to the same address in memory.
‫The difference is that your float is an address, so I can't just print out the value.
‫So if I wanted to do a u log and I wanted to say your float value is equal to percent F, then I put
‫in your float.
‫This isn't going to work because your float is a pointer, not an actual float.
‫So what we need to do is essentially.
‫Get the value at that location.
‫So the way we can do this, if I were to store it in a new float variable called float value, then
‫I use the D referencing operator, which is actually a star as well.
‫And we put this before the thing that we want to d reference.
‫So we then give it a pointer to D reference, which in this case is your float.
‫Now it's a little bit strange that we use these stars in two different contexts.
‫So one, we're using the star after the type which tells us that it's a float pointer.
‫And when you're using it with a type, it means that it's a pointer.
‫When you use a star before a pointer expression, what you're doing there is you're saying, Get me
‫the value at this location.
‫So then that gets the value and copies it into float value and now float value.
‫We can just print out like so.
‫So with all those contortions, let's go ahead and compile it and see it in action.
‫Let's hit play.
‫And sure enough, it's saying your float value is five, which is the value we had originally.
‫Now, usually we don't store the intermediate value in a variable because that's wasteful.
‫It's creating a copy that we don't need.
‫So what we can do instead is just use that directly in the expression where we need it.
‫So your float value would be star, your float like so, and that's going to work in exactly the same
‫way, except this time it doesn't make a copy into a needless variable.
‫Now suppose we wanted to get the name of the owner actor here.
‫Well, the way we would do this, let's remove this stuff that we were doing with the floats is we would
‫d reference that owner pointer.
‫So we do star owner which actually gets us to the actor itself.
‫Then we can put a pair of brackets around the owner and then we can do a dot.
‫So we've got the actor out of this expression now we can use a dot to get something in from inside the
‫actor so we can do get actor, name or label, which is going to return us a f string so we can do f
‫string name equals to this and then we can print out mover owner percent SW And then instead of using
‫owner here, we're going to start name or then bring that.
‫We need to put the star in front of a name.
‫That's yet another use for that star operator.
‫We've already encountered three of them.
‫One is with this string.
‫That's the first time we've seen it.
‫Then it's here with the type and it's also here for D, referencing lots and lots of uses for exactly
‫the same character.
‫But that's how it is with C++.
‫Let's go and try it out and hit play.
‫And now you can see that it's printing out the name of the actors that the mover is attached to.
‫So we've gone reach through that pointer with the D referencing operator and been able to call a function
‫on a different object.
‫Now there's actually a much more compact syntax for doing this because it's so common for us to want
‫to get a function or property from a pointer object instead of having to do this with the parentheses
‫and as they d referencing operator, we can merge this all into one.
‫We can remove all of this or move the dot and instead we use this arrow operator so we do owner arrow,
‫get actor, name or label and this does exactly the same thing, except it's a lot easier to write.
‫So generally speaking will end up with the rule where if we have got a pointer, we use the arrow operator.
‫If we are using a struct like an F string or an F vector, we use the dot operator.
‫So I'd like you to print the actor's location using this new knowledge of how we can use pointers.
‫So I'd like you to call get actor location.
‫You're going to be using the arrow operator to look through the pointer and call that function on the
‫object.
‫At the other end, you're going to store the F vector that results from that.
‫Then you're going to call two compact string store the result in a new F string variable and print that
‫to the log.
‫Pause the video and have a go.
‫Okay.
‫Welcome back.
‫So I'm going to create a new F vector called owner location and I'm going to do owner arrow, get actor
‫location.
‫Then I'm going to convert this to a string.
‫So I'm going to have an F string called owner location string, and that's going to be equal to the
‫owner location dot to compact string like so okey doke.
‫So now we've got our own location string.
‫We can print that to the log.
‫I'm going to say that the mover owner is this with location percent s and that percent s we're going
‫to have another star owner location string like so and then hit control alt f 11 and we'll go ahead
‫and hit play and they go we have got both the name of the actor as well as its location printed out
‫as a string.
‫So now we can see the power of having pointers and being able to call functions on pointers.
‫It allows us to communicate between different instances of classes and makes our objects far more useful.
‫I'll see you in the next lecture.