Please help me understand how blackboards and blackboard keys work

From the tutorials i’ve seen none of them have explained this properly so i don’t understand how specific values from tasks get assigned to the right blackboard keys.

So let’s say i made a vector key with some arbitrary name in my blackboard, then in my task i get a vector value (for example player location) and goes into the input of Set Blackboard Value as Vector, and for the key input i make it a variable with another arbitrary name. Then in my behavior tree i set the AI to move to the player location by choosing said vector key, which gives it the player location.

But i don’t understand how does it know to get the vector value from that specific task? I used different names for the vector key in the blackboard and the Key input’s variable in the task, so there’s no connection there. What if i have several vector keys in my blackboard, and several tasks which each get a different vector value, and each one has a different name for the variable that goes into the Key input? How does it know which is which? I seem to be missing something here, and so far the tutorials i can find only explain what to do, but not why you do it or what it actually means, please help me understand.

You determine that in the Behavior Tree.

In your task, create a variable of type BehaviorTreeSelector. Since you’re looking for a vector, let’s call it “VectorKey.”

Now, in your Behavior Tree, click on the task so it is highlighted. That task will be highlighted and its parameters will appear in the Details pane. One of the variables in the details pane will be the variable that you created in the task (which should be called “VectorKey”). The drop down menu will show all of the various keys in your Blackboard. Choose the one that you want to feed the VectorKey variable in your task.

Thanks, that makes it much clearer! Though i wonder what’s stopping one from setting a vector in the task but choosing a different variable type in the behavior tree?

The variable type in the tree has to be a BehaviorTreeSelector, which is basically a generic type. You must then use a “GetValueAs______” to “cast” the key to whatever you are expecting. So, if your key is “VectorKey” and you set it as a vector, then in your task, you use “GetValueAsVector,” then you’ll get a vector value. If your task uses, say, “GetValueAsObject,” then the return value will be a nullptr because a vector isn’t an Object. It’s sort of like casting.

Thank you for the detailed explanation, it makes much more sense now!

1 Like