# How to get Blackboard Value from Query Owner?

**URL:** <https://forums.unrealengine.com/t/how-to-get-blackboard-value-from-query-owner/447173>\
**Category:** AI\
**Tags:** EQS, unreal-engine, question, CPP\
**Created:** [April 13, 2019, 4:45pm UTC](https://forums.unrealengine.com/t/how-to-get-blackboard-value-from-query-owner/447173 "2019-04-13T16:45:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Glomby](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Glomby](https://forums.unrealengine.com/u/Glomby)\
**Post date:** [April 13, 2019, 4:45pm UTC](https://forums.unrealengine.com/t/how-to-get-blackboard-value-from-query-owner/447173/1 "2019-04-13T16:45:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Glomby](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Glomby](https://forums.unrealengine.com/u/Glomby)\
**Post date:** [April 14, 2019, 4:15pm UTC](https://forums.unrealengine.com/t/how-to-get-blackboard-value-from-query-owner/447173/2 "2019-04-14T16:15:40Z")

</div>

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.
