‫Hello and welcome.
‫In this lecture, we're going to be setting up our first geometry trace so that when we go and look
‫at our gargoyle and we get close enough within range, then sure enough it prints out the name of the
‫actor that has been hit by the trace.
‫Let's dive in and see how we can do this so we're finally ready to tackle this sweep single by channel.
‫There was a lot of pieces that we had to have in place to make it work.
‫But finally, we're here.
‫So let's have a look at the syntax of this function.
‫So we are in a much better place to understand what was going on here when in these types.
‫So the return value is a boolean, which basically tells us whether or not we found anything with the
‫sweep.
‫Now the second argument, as you can see here, it's a reference.
‫It's got this ampersand.
‫And it doesn't matter whether there's a space after the ampersand or a space between the variable name,
‫it's all the same as long as there's an ampersand after the type saying that that type is a reference
‫and it's a type called an F hit result, you can see that it's a struct.
‫So this F hit result is the out hit.
‫That is the result that comes out of the sweep.
‫We can see what things have been hit and there's it's a struct because there's multiple different things,
‫pieces of information that can come out of this sweep.
‫Then we have a constant f vector reference.
‫So this is taking our start vector by reference instead of copying it.
‫Same with the end vector, then we've got a rotation.
‫So this is the rotation of the shape using an f quat, which is an alternative structure to using the
‫f rotator.
‫We'll see how we can basically just get put in a zero rotation here because we're using a sphere.
‫It doesn't really matter.
‫The next thing that comes in is the Trace Channel and we'll see how to figure out what our Trace channel
‫is called in C++.
‫And then we've got our collision shape, which will be the last argument we need to provide, and we'll
‫see how we can create a sphere of a certain radius by doing that.
‫But before we begin, we'll need to know what that radius is and how have it configured.
‫So we're going to go over into our grab a dot h, we're going to remove these functions we've been using
‫as examples for reference references and out parameters.
‫And we're going to create a new property which is going to be edit anywhere and it's going to be a float
‫called the grab radius and we're going to set that to 101 metre.
‫So let's go over into the C++ now and remove the references to print damage and has damage and we can
‫remove any of that from the tick component as well.
‫The whole if statement and where we're passing in the damage because here we're drawing our debug line
‫and now we want to make a call to our sweep single by channel.
‫So we're going to type sweep.
‫So we're going to type get world parentheses because we know that this is a function on the new world
‫object.
‫Then we can do an arrow because we know that get world returns a pointer and then we're going to do
‫a sweep single by channel like so and we're going to have to input an out parameter for it to populate
‫as the first argument here.
‫So we're going to create a variable that's going to be empty, that will be populated, and it's got
‫to have the right type.
‫So it's going to be an if f hit result and we're just going to call the variable itself hit result,
‫put a semicolon at the end because we're not initializing it, we're not giving it any value, but we're
‫going to pass it in for it to be given a value by the sweep single by channel function.
‫So that's our hit result.
‫Then we need to pass in the start and end vectors which we know are going to be not copied but taken
‫a reference to.
‫Now we need to populate the rotation which we can do with a simple f quote colon, colon identity,
‫which tells us basically that this is a no rotation.
‫That's just a bit of a weird language for it.
‫It's a mathematical speak for meaning that this is no rotation.
‫Next up, we need the trace collision channel.
‫Now, how do we go about finding that trace collision channel?
‫Well, if we go over to the folder that holds our project and we go in to config and then we go to the
‫default engine INI right, click that and go open with Visual Studio code.
‫And in here I'd like to search for Grabber.
‫So you'll be able to see the collision response channel for the grabber.
‫And it's basically been set up here in the default engine INI.
‫It's only mentioned once in the whole file and you can see the channel name.
‫This is the channel name in C++.
‫It's not very.
‫Yes, but it's s.e.c.
‫Game Trace Channel two, so we can go ahead and copy that, and then we can go back to our grab a CP
‫and paste it in here as the trace channel that we want.
‫Now, this line is getting rather long, and what we can do to compensate for that is we can actually
‫put each of these parameters on separate lines, or at least spread them out.
‫So maybe the start and end are on the same.
‫The identity criterion is on one line, the trace channel is on another line like so.
‫And that just gives us a little bit more space for reading these long argument lists.
‫Now, if we head back to the documentation, we can see that the next thing we need to pass in here
‫is an F collision shape.
‫So we need to construct a shape.
‫Maybe we'll do this as a separate variable up at the top.
‫I'll just do it before the F hit result to make it super clear that the F hit result is actually an
‫out parameter.
‫I'm always going to leave that as the last thing before the call to the function.
‫So we're going to create an F collision shape, which we're going to call the sphere, and we're going
‫to set it equal to F collision shape, colon, colon, make sphere.
‫So that's going to create us a new sphere, collision shape.
‫And the argument to this function is the sphere radius which we have got as the grab radius variable
‫that we've configured as a U property but a semicolon on the end of this line and we can pass in the
‫sphere as our final argument to the sweep channel function and put a semicolon at the end of that line.
‫Now one more thing is that this function we know returns a boolean, which is whether we've hit anything.
‫So I'm going to put the result into a boolean variable called has hit and that's what we're going to
‫be using later on in this function.
‫So I'd like to challenge you to print the hit actor's name.
‫So now we've got this sweep happening.
‫We should be able to get some results out of it.
‫So use an if statement to print if we have anything at all.
‫So if that boolean is true, that's when we're going to print out the actor name.
‫You're going to get the actor that the Sphere Trace is hit by using the hit result struct.
‫It's got a method on it which you can access with a dot operator because it's a struct in.
‫It's not a pointer to the struct.
‫You can do a dot, get actor and use the parentheses and that returns you an actor pointer.
‫Then using that active pointer, you can get the actor's name using the get actor name or label method
‫and think about whether you want to use the dot or arrow operator for this and then compile and test
‫having printed out that actor name and see what you can hit in the scene.
‫Pause the video and have a go.
‫Okay.
‫Welcome back.
‫So we're going to start off with creating that if statement.
‫So if has hit, then we're going to put some braces and we're going to do first of all, we want to
‫get hold of that actor point.
‫So a actor star hit actor is equal to the hit result.
‫Dot get.
‫Actor.
‫Parentheses.
‫Like.
‫So then we're going to do a u log and we're going to write hit actor colon percent sx and we can do
‫hit actor and because it's a pointer here, we can do hit actor arrow, get actor name or label, then
‫some parentheses.
‫And because this is a string, we have to put a star at the front of the whole shebang so that it can
‫properly display it in our Yui log.
‫Okay, so we now need to just go ahead and compile this.
‫Then once we're in the scene, let's open up the output log and dock it to the layout so we can see
‫it while we play and hit the play button.
‫And instantly you can see that we are hitting that gargoyle statue.
‫If I turn around and look at something else you can see, well, it's not very clear whether I'm not
‫hitting anything or whether it's displaying nothing.
‫So what I'm going to do is I'm going to put in an else to our if statement here, put some more brackets
‫and I'm going to do another U log.
‫And this time the text is going to say, no actor hit, let's recompile and go and play in the editor.
‫And you can see it now.
‫It's saying no actor hit all the time until I go and start looking at the gargoyle.
‫And now it's saying that the gargoyle is the thing being hit.
‫If I move too far back out of there for me to range, you can see I see that it's saying no actor being
‫hit again.
‫Great stuff.
‫So we have now done a geometry sweep with a spherical object and we can see that it is indeed reacting
‫only to the actors in our particular Trace channel, such as the Gargoyle is the only one that we set
‫up at the moment.
‫So that's the only one that it's finding.
‫I'll see you in the next lecture.