C++ Behavior Tree Service Not Updating Blackboard

Since there is no documentation on this. Can someone point out why this code is not updating my blackboard? It makes no sense.

void UBTService_AdmiralUpdateQueue::TickNode(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory, float DeltaSeconds)
{
	Super::TickNode( OwnerComp, NodeMemory, DeltaSeconds);
	UE_LOG(LogClass, Log, TEXT("Service Ticking."));
	if (OwnerComp.GetAIOwner())
	{
		UE_LOG(LogClass, Log, TEXT("Has a Controller."));
		//Get the AI Controller
		AAdmiralAiController* Controller = Cast<AAdmiralAiController>(OwnerComp.GetAIOwner());
		if (Controller)
		{
			UE_LOG(LogClass, Log, TEXT("Successful Cast."));
			//If Queue is bigger that 0.
			//Set blackboard keys to true.
			//PlayerQueue
			if (Controller->GetPlayerQueueSize() > 0)
			{
				/* The selected key should be "bPlayerQueue" in the BehaviorTree setup */
				OwnerComp.GetBlackboardComponent()->SetValue<UBlackboardKeyType_Bool>(SubmarineBlackboardKey.GetSelectedKeyID(), true);
			}
			else
			{
				/* The selected key should be "bPlayerQueue" in the BehaviorTree setup */
				OwnerComp.GetBlackboardComponent()->SetValue<UBlackboardKeyType_Bool>(SubmarineBlackboardKey.GetSelectedKeyID(), true);
			}
}}}

You have both sides of your ‘if’ statement setting the bool value to ‘true’. Try setting line 24 to ‘false’.

Also, I’m not sure how GetSelectedKeyID is supposed to work at runtime. Instead of using “GetSelectedKeyID”, try using:

uint8 BlackboardKeyID = Blackboard->GetKeyID(DesiredKeyFName);
OwnerComp.GetBlackboardComponent()->SetValueAsBool(BlackboardKeyID,  true);

The DesiredKeyFName will be something like:

FName DesiredKeyFName(TEXT("PlayerQueueNonZero")); // or whatever you called it in the blackboard exactly

Hey rantrod, i just but both to be true to see if any would alter the default false option inside the blackboard.

The answer actually was i hade to Cache the blackboard key.

I have to override this function and cache all blackboard values that i’m using.

void UBTService_AdmiralUpdateQueue::InitializeFromAsset(UBehaviorTree& Asset)
{
Super::InitializeFromAsset(Asset);
SubmarineBlackboardKey.CacheSelectedKey(GetBlackboardAsset());
PowerupBlackboardKey.CacheSelectedKey(GetBlackboardAsset());
MedalBlackboardKey.CacheSelectedKey(GetBlackboardAsset());
}

Thanks for posting this. That would have definitely been a gotcha for me.