‫Hello and welcome.
‫In this lecture, we are going to be setting a blackboard key from our C++ so that we can set the player's
‫location at Begin Play.
‫Let's dive in and see how that works.
‫Okay.
‫So as I said in the last lecture, we want to be able to set some state from our gameplay in the blackboard
‫for the AI to act upon.
‫So the blackboard looks like this and it currently has this self active key, but it doesn't have any
‫other keys here.
‫We can add keys like clicking on this new key button.
‫You can change the type.
‫There isn't actually a type for actors or anything like that that just goes under the nebulous type
‫of object for everything else.
‫There's balls, classes, enemies, etc. but you can choose what kind of type that you want that object
‫to be by going to your blackboard details, dropping down and choosing what base class you'd like.
‫So for example, it's saying here that the self actor is of actor type.
‫This has just been put in here by default.
‫But what we want to do here is set a new key.
‫And to do that, we need to do find out how we can gain access to this in the C++.
‫So we already have an easy function that allows us to get hold of the blackboard by doing a get blackboard
‫component on the AI controller.
‫So simple as we can just do get blackboard component and let's have a look at that blackboard components
‫dot h and have a look what is available in here.
‫We want to be doing something like set key or set blackboard or in fact, it's as simple as just set
‫value.
‫So here you've got a bunch of different functions on that blackboard component that allow you to set
‫these different values so you can do it by a key name, which is an F name here.
‫Then you can set the value as an object, or you can set the class all of the different types that are
‫available here.
‫So let's give that a go.
‫I'm going to go over to the C++ and try and set our player pawns location as one of the variables.
‫So we're going to do first of all, we need to get hold of the blackboard component.
‫So let's give that a shot, get blackboard components.
‫Then we need to have the right includes.
‫So if I hover over the blackboard component on H, you can see that we need to be including behavior
‫tree forward slash blackboard component.
‫So let's do that hash include then it's going to be the behavior tree forward slash blackboard component
‫H.
‫Now we can use the arrow operator on that type and we should be running.
‫We want to, in this case be setting a vector.
‫We want to set the location.
‫So we're setting a vector and not copy the whole line, but just set the vector and then we want to
‫what's the first parameter is the name that we're trying to set so we can use our text macro for that.
‫And I'm going to call it the player location that's going to give us the location at the start because
‫we're calling it in Begin Play and then we need to actually set the location so we can get that from
‫the line of code, getting our player -- first and foremost.
‫So uncomment that and then we want to do the player pawn arrow and get actor location like so and finish
‫off the line with the semicolon.
‫And it's as simple as that to go ahead and set a blackboard value.
‫So your challenge is going to be to do the other half of this, which is to create a key in the blackboard.
‫So add the key to the blackboard, make sure it's of the right type, the right name, and then if everything
‫worked correctly, you should be able to check that value at runtime.
‫Remember last lecture?
‫We saw how we can see the behavior tree.
‫You can do the same thing.
‫You can inspect the blackboard at runtime when you're playing and you should be able to see what value
‫was set by the C++ code.
‫Pause the video and have a go.
‫Okay.
‫Welcome back.
‫So I'm going to go over in to the editor hit compile because I haven't done that already.
‫And we're going to add a new blackboard key.
‫And in this case, we have to get the names right and the types right, otherwise things will go wrong.
‫So we've got a vector key which we're going to be calling our player location, and I'm going to copy
‫that to make sure that we have got the right spelling here.
‫Yes, we have cool beans.
‫And then what we're going to do is we're going to head over and just check that the blackboard details
‫are okay.
‫So yeah, there's a name you could add a description if you wanted.
‫The type is a vector.
‫That's cool.
‫For instance, select.
‫This is a variable that we're not particularly interested in at the moment.
‫Cool.
‫We've got our code has compiled, so let's go and hit play and see whether we can inspect that blackboard
‫value.
‫Go over to the blackboard and you can see we can still have that dropdown of choosing which I, we want
‫this to relate to.
‫We've only got one in our world, but you can see that self actor hasn't been set, but the player's
‫location has indeed been set.
‫Let's check if that is roughly correct.
‫If I f h d possess, have a look at my player and have a look at the player's location.
‫You can see that.
‫Yes, it's pretty much correct.
‫2000 -5100.
‫So that's setting the value through from C++.
‫Simple as that.
‫We can start to see how we can interface with our behavior trees.
‫In the next lecture, we're going to look at the actual structure of behavior trees and making them
‫do something.
‫The exciting part.
‫See you there.