How do you determine which Key on a Blackboard you are accessing?

I’m having a problem setting keys on my Blackboard when I have multiple Keys. If I can just sort this out, I’ll have a fairly easy time setting up my BehaviorTree. I seem to only be able to set the first Key’s value when using the function “Set Blackboard value as ______”. Can anyone give me a code/blueprint example of how to set multiple keys in a blackboard? Thanks.

Reposting here after answering this question on another thread:

If you’re writing C++ code:

You can fetch a uint8 Blackboard KeyID by using an FName that matches the key in the blackboard:


uint8 BlackboardKeyID_Enemy = Blackboard->GetKeyID(EnemyKeyName);

Then you can set values using the appropriate function for the type of key, such as:


Blackboard->SetValueAsObject(BlackboardKeyID_Enemy,  EnemyPawn);

(Also, SetValueAsEnum, SetValuesAsClass, SetValueAsVector, SetValueAsName, SetValueAsInt, SetValueAsFloat, SetValueAsBool, etc. See BlackboardComponent.h for the functions). There are corresponding GetValueAs… functions there as well.

If you’re using blueprints:
The functions above (SetValueAs… and GetValueAs…) are all also exposed as nodes in blueprints which can be called from within Behavior Tree blueprint node objects (decorators, tasks, services).

In the blueprint, you can use a variable of type BlackboardKeySelector and set it as Editable to expose the selection to the details view from within the behavior tree itself. That will let you pick a valid entry from the blackboard you are using within the behavior tree (from a dropdown list). Pass that variable into the “Key” input on the Set/Get node.

Just use separate BlackboardKeySelectors and/or separate KeyNames/KeyIDs to get or set multiple entries in the blackboard.

LOL I cant freaking believe I overlooked that all weekend. Seriously? That’s how easy it was? I kept overlooking the “PointKey” selection on the behavior tree itself. Kill me now.

Got a foundation for my behavior tree traversing properly in 30-45min using blueprints after reading your post. Now I just need to go through and code the functionality. THANK YOU.

another question: How do you get a class extended from UBTService_Blueprintbase to show up as a Service inside the Behavior tree? I tried overriding and calling the TickNode function but I got all sorts of errors…but now that I mention it I MIGHT have extended from UBTService_Blackboardbase instead… (can’t check at the moment because I’m at work)

I noticed that BTTasks are exposed to the Behavior Tree by overriding ExecuteTask (?):
virtual EBTNodeResult::Type ExecuteTask(UBehaviorTreeComponent* OwnerComp, uint8* NodeMemory) const OVERRIDE;

so would I add:

virtual void UBTService_Blueprintbase::TickNode(UBehaviorTreeComponent* OwnerComp, uint8* NodeMemory, float DeltaTime) OVERRIDE;

to my .h file?

The Service only seems available on the right click context for a composite node, they are the green nodes.

I’ve been working on BP only Behavior Trees and have the Tasks all working easily, with Blackboards, but… I’m not using the service nodes correctly. But, I can create them and add them to composite nodes.

Did you extend a script from BTService_Blueprintbase and have it show up when you right click a composite note -> service? Did you have to do anything special to get it to show up?

I’ve only gotten them to work through blueprints. Also…what is the function name to call inside your .cpp to get the Service to run?

TickNode()?

Ok I’ve got all this working, but how do you get the AI to animate when it is attacking for example? Can’t seem to pass the right blackboard variables to the animGraph in a way that works. :frowning: Any help would be awesome!

Wrong section