How to get Blackboard Value from Query Owner?

Hi,
I’m completely new to programming with C++ in UE4 but since I need a lot of AI I can’t just do everything in Blueprints.

So I’m using the Environment Query System to get Actors of a specific Class but I need to perform some extra tests within the generator so I created a custom generator based an the ActorsOfClass one. Now I need to check a Blackboard bool value inside this generator and there seems to be a queryowner which should be the AIController I guess. But how do I get the Blackboard Value from that QueryOwner?

I know this is a very basic question but I’m basically helpless in C++ right now.

I’m not even sure if the QueryOwer would give me the blackboard key, this is how it is defined:

UObject* QueryOwner = QueryInstance.Owner.Get();

I guess I would need to right includes to be able to cast this to the ai controller and get access to the blackboard functions first.

1 Like

Okay I figured it out: If I cast the QueryOwner to a APawn I can get the controller of that pawn and cast it to an AIController from which I can get the Blackboard and whatever Blackboard Value I want. I feel like this is far from being pretty but It works.

APawn* OwnerActor = Cast<APawn>(QueryOwner); 
if (OwnerActor != nullptr)
{
    AAIController* contr = Cast<AAIController>(OwnerActor->GetController());
	if (contr != nullptr)
	{
		UBlackboardComponent *bb = contr->GetBlackboardComponent();
		if (bb->GetValueAsBool(bbName) == false)
		{
			//Do stuff
		}
	 }
  }

EDIT: I’m currently doing this in a for loop which isn’t great with all the casting going on. I would love to do it only once but an EnvQueryGenerator doesn’t have an InitializeComponent function as it seems so I don’t know how to do the casting part of this only once.

3 Likes