x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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:

alt text

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++?

Product Version: UE 4.14
Tags:
log.png (9.7 kB)
more ▼

asked Jan 31 '17 at 07:19 PM in C++ Programming

avatar image

MaDNeoN
8 1 5

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

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

more ▼

answered Feb 04 '17 at 07:27 PM

avatar image

MieszkoZ STAFF
7.3k 223 56 408

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question