Blackboard SetValue returns true, but GetValue always returns 0

I have defined a blackboard data asset in the editor and want to set its value in my GameMode. Then I want to get that value in an AIController that also uses the same data asset.

GameMode.cpp

ABadBlackboardGameMode::ABadBlackboardGameMode()
{
	static ConstructorHelpers::FObjectFinder<UBlackboardData> DataAsset(TEXT("BlackboardData'/Game/SOAPGOAP/WorldState.WorldState'"));
	BlackboardDataAsset = DataAsset.Object;

	Blackboard = CreateDefaultSubobject<UBlackboardComponent>(TEXT("BlackboardComponent"));
	Blackboard->InitializeBlackboard(*BlackboardDataAsset);

	Blackboard->PauseUpdates();

	FName Name = FName("ActorIsHungry");
	uint8 keyid = Blackboard->GetKeyID(Name);

	bool WasAdded = Blackboard->SetValue<UBlackboardKeyType_Int>(keyid, 111);

	if (WasAdded)
	{
		UE_LOG(LogTemp, Warning, TEXT("Set %s to true"), *Name.ToString());
	}

	Blackboard->SetValueAsInt(Name, 111);
}

And the AIController.cpp:

ABadBlackboardAIController::ABadBlackboardAIController()
{
	static ConstructorHelpers::FObjectFinder<UBlackboardData> DataAsset(TEXT("BlackboardData'/Game/SOAPGOAP/WorldState.WorldState'"));

	BlackboardDataAsset = DataAsset.Object;
	Blackboard = CreateDefaultSubobject<UBlackboardComponent>(TEXT("BlackboardComponent"));
}

void ABadBlackboardAIController::BeginPlay()
{
	Blackboard->InitializeBlackboard(*BlackboardDataAsset);

	uint32 NumberOfEntriesInBlackboard = Blackboard->GetNumKeys();

	UE_LOG(LogTemp, Warning, TEXT("Number of keys: %d"), NumberOfEntriesInBlackboard);

	FName Name = "ActorIsHungry";

	//uint32 Value = Blackboard->GetValue<UBlackboardKeyType_Int>(Name);

	uint32 Value = Blackboard->GetValueAsInt(Name);

	UE_LOG(LogTemp, Warning, TEXT("%s: %d"), *Name.ToString(), Value);

	if (Blackboard->GetValueAsInt(Name))
	{
		UE_LOG(LogTemp, Warning, TEXT("Displayed as 0, but has a non zero value"));
	}
}

Now whenever I run this, the output looks like this:

124348-log.png

The .h files also include the UBlackboardComponent and UBlackboardData, as well as BlackboardKeyType_Int.

So my problem is: how do I set a value to a blackboard I made in the editor and then retrieve it using C++?

This is not how BB assets work. The asset just defines the “shape” of the blackboard, but every BB component has a separate instance of a BB of this “shape”. Setting a value in one instance does not affect other instances… unless you mark the given BB key as “synchronized” - if so then any change to it should be propagated to other instances of the same BB asset.

Cheers,

–mieszko