I was making a decorator in c++ I used 2 approaches 1 using a blackboard component and another taking values directly from the pawn. I want to know why should I use a black board component form something like this.
Without BB
bool UBTDecorator_Test::CalculateRawConditionValue(class UBehaviorTreeComponent* OwnerComp, uint8* NodeMemory) const
{
UBehaviorTreeComponent* MyComp = OwnerComp;
AMyAIController* OwnerController = Cast<AMyAIController>(MyComp->GetOwner());
AMyBotCharacter* Pawn = Cast<AMyBotCharacter>(OwnerController->GetPawn());
GEngine->AddOnScreenDebugMessage(-1, 0.05, FColor::Black, Pawn->bIsSelected ? TEXT("true") : TEXT("false"));
if (Pawn->bIsSelected)
{
GEngine->AddOnScreenDebugMessage(-1, 0.05, FColor::Black, "works2");
return true;
}
return false;
}
Using BB
bool UBTDecorator_Test::CalculateRawConditionValue(class UBehaviorTreeComponent* OwnerComp, uint8* NodeMemory) const
{
UBehaviorTreeComponent* MyComp = OwnerComp;
AMyAIController* OwnerController = MyComp?Cast<AMyAIController>(MyComp->GetOwner()) : NULL;
const UBlackboardComponent* MyBlackboard = OwnerComp->GetBlackboardComponent();
bool bIsSelected = true;
auto MyID = MyBlackboard->GetKeyID(BotSelectedKey.SelectedKeyName);
auto TargetKeyType = MyBlackboard->GetKeyType(MyID);
if (TargetKeyType == UBlackboardKeyType_Bool::StaticClass())
{
bIsSelected = MyBlackboard->GetValueAsBool(MyID);
}
if (bIsSelected)
{
return false;
}
return true;
}
Both do exactly the same thing. I want to why should I use the baclboard