Blackboard Keys on C++

Hi! I’m transitioning from Blueprints to C++ and I’m trying to use blackboard keys on my service but I’m not sure how to do it and I can’t find proper documentation for it.
What would be the equivalent of a Blackboard key selector on C++ and get/set blackboard value as x?

Thanks in advance

2 Likes

Within your C++ you’d define a property such as:

FBlackboardKeySelector MyBlackboardKey.

Then you end up with:

I.e: ExecuteTask(UBehaviorTreeComponent& OwnerComp,…)
UBlackboardComponent* MyBlackboard = OwnerComp.GetBlackboardComponent();
MyBlackboard->ClearValue(Key.SelectedKeyName);
MyBlackboard->GetValueAsBool(Key.SelectedKeyName);
​​​​​​​MyBlackboard->SetValueAsBool(Key.SelectedKeyName, false);

3 Likes

Thanks! Sorry for the late answer. I was expecting an automatic notification or something like that but then I noticed I wasn’t subscribed to the thread

To be 100% accurate, in this particular example it should be:



UBlackboardComponent* MyBlackboard = OwnerComp.GetBlackboardComponent();
MyBlackboard->ClearValue(**MyBlackboardKey**.SelectedKeyName);
MyBlackboard->GetValueAsBool(**MyBlackboardKey**.SelectedKeyName);
MyBlackboard->SetValueAsBool(**MyBlackboardKey**.SelectedKeyName, false);


The variable “Key” appeared out of nowhere and might be misleading.

Also, you should declare the key as **public **and with below property to make it editable in the editor:


UPROPERTY(EditAnywhere)
FBlackboardKeySelector MyBlackboardKey;