‫Hello and welcome.
‫In this lecture, we're going to be looking at how we can create new nodes in Blueprint from our C++
‫so that essentially we can be calling C++ functionality from within Blueprint.
‫Let's dive in and see how it's done.
‫Now, it's all well that I can use blueprints to call to blueprint nodes, but I actually want to activate
‫our grabber from this piece of blueprint here, not print out some strings.
‫So how do I go about doing that?
‫Well, fortunately, we can quite easily expose a function from a C++ class in to blueprint.
‫And the way we do this is as follows.
‫So we're going to go and create a new public function.
‫So I'm going to go to my public section just under the tick component.
‫And here I'm going to create a new function with a void return type called release.
‫So we're going to do grab later on, but we're just going to call a release function for now.
‫How do I make this available in Blueprint?
‫Well, I need to make it a U function.
‫So you've got you properties for variables.
‫You function is kind of the equivalent for making a function basically visible in the land of blueprint.
‫But we don't stop there, just like with the new property.
‫We have to make it edit anywhere here with the u function we have to make it blueprint callable and
‫that, as the name suggests, means that this function now becomes a node that blueprint has access
‫to.
‫So let's go over to the grab a CP and create an implementation for this.
‫It's going to be void return type.
‫It's going to be a U.
‫Grabber, colon, colon release, no parameters.
‫And we'll put a function body, which I'm going to stick a u log in and I'm going to give the message,
‫be released grabber like so and then we can compile and back in our beep.
‫Player I'm going to delete the print string node and I'm going to drag off of released here and I'm
‫going to search for release as a function in here.
‫Now let's go and have a little bit of a look around.
‫Nothing's showing up at the moment because I need to do this on the grabber.
‫So let's take the grabber component, drag it into the event graph to create a grabber variable, then
‫drag off of this and search for release.
‫Now, you notice nothing's coming up in this case either.
‫And that's because we've used live coding and sometimes things that are compiled in live coding do not
‫show up in the editor.
‫What we have to do is close down the editor, close down the live coding window and then in Visual Studio
‫code, hit control shift B and build using the Crypt Raider editor win 64 Development Build.
‫Wait for that to succeed and then relaunch the editor from the new project file.
‫Now if we reopen our BP player and now dragging off the grabber, we search for release.
‫You can see that now there is a node called release.
‫And indeed all that's going to do is going to call as C++.
‫So you can see how you can really use Blueprint and C++ in close collaboration this way by exposing
‫C++ things into the Blueprint world.
‫Now I'm going to connect up my release execution pin to the release node.
‫We're going to go in to our dungeon and we're going to hit play.
‫And now if I were to grab and then release, you can't see anything because it's in the output log.
‫So let's open up the output log and dock it to the layout, then hit play again.
‫And now when we grab and then we release, you can see there is a brief message there.
‫It scrolls by really quickly because every tick we are doing this hit gargoyle status statue thing.
‫But there if you stop and look back through the log, you can see it said released grabber.
‫So our C++ code is being executed.
‫Okay, so now I'd like you to move our sweep code in to a grab function.
‫So you're going to create a grab function and call it from Blueprint.
‫You're going to do it the same way as I just did the release function.
‫But when you create the body of the grab function instead of just printing anything, let's move that
‫sweeping code and the if statement and all the prep variables from TIC so that it's not doing it.
‫Every single time we tick to just when we call that grab function, when we press our mouse button down
‫or press a trigger on our controller, so then recompile and check the logs to make sure that indeed
‫that's only happening when you press the button, pause the video and have a go.
‫Welcome back.
‫So let's go in to our C++ and up to our header file.
‫I'm going to close down the compile window here and above release.
‫I'm going to create a new U function blueprint, callable, which is going to be void called grab and
‫we're going to implement this over in the C++.
‫So again, it's going to be a void.
‫You grab a colon, colon grab parentheses and then braces.
‫And I'm going to move all of this code from TIC component because we are setting up our start vectors
‫and all that sort of good stuff.
‫Let's go all the way down and cut it out and paste it into grab instead where it should be.
‫Just fine.
‫Now let's see if live coding will bring about the function in the BP player.
‫Let's go over to the beep player, delete our print string and let's drag off that.
‫Grab a node we've got and see if we can find a grab function.
‫Okay, so this time the grab function was available to us.
‫That's great.
‫Now let's hook up the pressed execution pin, go over to our dungeon, hit play and make sure we scroll
‫down to the bottom of the output log.
‫Going to right click into my viewport and have a look around and then I'm going to press my left button.
‫It says No actor hit and then instantly the release grabber, so no actor hit.
‫And then I release the key, no release grabber.
‫Now if I go up to my gargoyle, I'll have a look at it.
‫I press on it and it says Actor hit Gargoyle Statue and then I can release the grabber.
‫So now we've got the right sort of architecture in place in order to grab this gargoyle.
‫Next, we need to deal with the physics part of this setup.
‫I'll see you in the next lecture.