How to simply set a Blackboard Key

Hello all.

Was wondering how to simply set up a blackboard key in the AI Behavior Tree. For instance, I have a key type object where the base class is Actor, and I want that key to somehow be set to the Actor I have within the game. In the behavior tree, I simply just want the AI to move to that actor. I looked at the documentation and tried to google how to simply set blackboard keys but there doesn’t seem to be a simple explanation.

Thanks.

Hey Azsarg! Welcome to the forums!

So the problem is you’re wanting to set a BB variable pre-level-begin.

On your AI Controller, you can set BB values. I would suggest making a variable matching the type of variable on the BB on the AI controller itself. You’ll make that variable “Instance Editable.”

Now, once you have done that,

  1. you can go into your level,
  2. select your character that exists in the level,
  3. use the details panel to find that open variable
  4. grab the object you’re wanting to move towards and place it into that variable slot.
    At this point, you have a reference in the AI Controller. Next,
  5. Go into the AI controller’s event graph. On “OnPossess”, put a “Set BlackBoard Value” node in, and use your new variable to set your BB value!

So the object reference goes from
In Level → AI Controller → BlackBoard → Behavior Tree :slight_smile:

Thank you for the reply!! I am quite new to Unreal, so I am not sure what the process for making and setting the BB values within the AI Controller(Or rather, within a blueprint)

Also just to add, I am working within the Lyra Project and there is already an Event OnPossess within the AI controller that is connected to something else.

If you are indeed new enough to unreal to have a need to learn these things, that’s okay! However, I would stay a bit farther away from AI until you get a handle on the basics, it tends to have many systems working together… I didn’t pick up Behavior trees for several months of daily development, and even then I used a ton of tutorial material.

So let’s get you to where you understand those individual systems first! :slight_smile: I suggest starting with this tutorial:

Then I’d move on to this talk here where they walk through setting up an AI character with a behavior tree and blackboard.

Keep in mind, no, you’re not looking for the specific solution to your problem yet, you’re expanding your skillset to know what you CAN do, how to implement something instantly, and by proxy more than likely figuring out how to do exactly what this question was all about :slight_smile:

Thank you! I have some experience with unreal(IE making a mini game and the such) though I guess I meant I am quite new when dealing with AI haha.

No worries!
Sorry, did you say you don’t know how to set a variable in the AI controller or a blueprint as well as in a Blackboard? Did I not understand that correctly? :grimacing:

Oh no! I am saying I do know how to set a variable in a blueprint and a typical AI Controller. However the process of setting blackboard keys is something I need help with, especially since I am trying to do it with the Lyra Project for the Bots AI Controller.

Okay then!

As far as Lyra, I don’t know what would make it any different. But to set a blackboard key, you just use “Set BlackBoard Key as ___” node, and make sure everything is named IDENTICALLY or it will screw up. Even a space at the end will ruin it.

Oh, and there’s no reason you can’t throw this on the “OnPossess” with the other stuff that’s there already.

I managed to make a Set blackboard value as object node and promoted the key and value inputs into variables. However, when assigning them, the enemy is still not moving to the actor I wanted it to move to.

I’ve attached the blueprint I am setting the variables (which I made into a service into the behavior tree and the part of the behavior tree that I made that is currently running.


The target variable “Move Right” is actually being set to the object I specified in the service blueprint, but for some reason the sequence stops right when it gets to the Rotate Node in the Behavior tree and doesn’t progress, which is making me think its actually not being set to the object within the scene?

Hey again @Azsarg!

Yes, that is for sure something that is happening. You need your variable to default to “None”. You will set it individually, by making the variable Instance Editable (see my first post).

Unless… Are you spawning the AI’s? Or are they set in the level pre-gameplay, as I was assuming?

Hey Mind-Brain.

Thanks for all of the suggestions. I actually just now figured it out by just tagging the object I wanted it to move to and within the Service Blueprint setting the Move Right variable to the tagged object.

Thank you!