Making a Dectorator in c++ How to get value from a FBlackboardKeySelector

I am trying to write a decorator in c++. I want to know how to get a value from a FBlackBoardKeySelector something that can be easily done in BP.


Hey envenger

I realize this is an old question but I just came across it and thought I’d answer it in case anyone else is looking for the answer.

Assuming the blackboard comp has been correctly set up and you have the header files, you can do something like this;

APawn* BlackboardPawn = Cast<APawn>(BlackboardComp->GetValueAsObject(TargetID));

You can write the functions in the AI class that you’re using, and then make decorators/tasks that use the functions in the BP…

or maybe created the class directly from BTDecorator, in it there already a method that give us access to blackboard component try to look at :

in there it had seeral method that gives you blackboardcomponent like OnNodeActivation, calculateRawCondition etc.

To Do This :

1. Make A C++ Class From “UBTDecorator” Name "UBTD_IsEnemy"

2. Go To “UBTD_IsEnemy.h” Override This Function "CalculateRawConditionValue"


	virtual bool CalculateRawConditionValue(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) const override;

3. Now Go To UBTD_IsEnemy.cpp

#include "PerceptiveAI_Shooter/AI/UBTD_IsEnemy.h"
#include "PerceptiveAI_Shooter/AICharacterBase.h"
#include "BehaviorTree/BehaviorTreeComponent.h"
#include "AIController.h"

bool UBTD_IsEnemy::CalculateRawConditionValue(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) const
	bool bSuccess = Super::CalculateRawConditionValue(OwnerComp, NodeMemory);
	if (!bSuccess) return false;

	AAICharacterBase* AIPawn = Cast<AAICharacterBase>(OwnerComp.GetAIOwner()->GetPawn());
	if (AIPawn)
		UE_LOG(LogTemp, Warning, L"ActorOwner Name : %s, Controller : %s ", *AIPawn->GetName(), *AIPawn->GetController()->GetName())
	return true;

4. The Decorator Condition Depends On This Function CalculateRawConditionValue

5.Now You Can Add This Decorator In BehaviorTree.