Understanding UseBlackboard c++ signature

Hey!

I’m trying to use the UseBlackboard function of the AAIController, but I can’t quite figure out the second parameters.
Here’s the signature:

/**
	 * Makes AI use the specified Blackboard asset & creates a Blackboard Component if one does not already exist.
	 * @param	BlackboardAsset			The Blackboard asset to use.
	 * @param	BlackboardComponent		The Blackboard component that was used or created to work with the passed-in Blackboard Asset.
	 * @return true if we successfully linked the blackboard asset to the blackboard component.
	 */
	UFUNCTION(BlueprintCallable, Category = "AI")
	bool UseBlackboard(UBlackboardData* BlackboardAsset, UBlackboardComponent*& BlackboardComponent);

I’ve made a class that inherit UBlackboardComponent , created an instance with CreateDefaultSubobject method which return a UBlackboardComponent pointer. But I can’t find any way for the UseBlackboard method to accept it.

Anything I’m missing?

(I’m not at home, but I’ll add some code later to make sure it’s clear)

UPDATE:

It wasn’t that simple, but I made it work. In fact, you have to pass à pointer to an UBlackboardComponent, but the trick is that classes that inherit from UBlackboardComponent doesn’t seem to work. From my point of view, it seems weird, but maybe someone has an explanation? Cause my idea in the beginning was to design a class that inherit from UBlackboardComponent and have it configure his data set. So I would have a class that contain both and that is easy to work with. Instead, I had to move everything in my AIController. It seems like bad practice since the AIController has too much responsibility right now. Any idea?

Hi there !

I was asking myself the same question and I think I just got it by reading what the function actually does. So I answer you even if your question is 2 years old, just in case it helps.

The first parameter BlackboardAsset is the input parameter that actually points to the blackboard asset you designed. So you can get it for example with a :
UBlackboardData * Data = Cast(StaticLoadObject(UBlackboardData::StaticClass(), nullptr, TEXT("/Game/ReferenceToBehaviorTreeAsset")));

The second parameter is a return parameter. That is why it is a pointer reference. If you read the function code, you’ll see that the function only use it to set its value at the end. So in my understanding, unless you want several AI to share the same blackboard, you can just initialize an empty variable of the right type and pass it.