# How to use EQS in c++

**URL:** <https://forums.unrealengine.com/t/how-to-use-eqs-in-c/368003>\
**Category:** AI\
**Tags:** EQS, unreal-engine, question, CPP\
**Created:** [August 23, 2016, 12:47pm UTC](https://forums.unrealengine.com/t/how-to-use-eqs-in-c/368003 "2016-08-23T12:47:25Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xavice](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Xavice](https://forums.unrealengine.com/u/Xavice)\
**Post date:** [August 23, 2016, 12:47pm UTC](https://forums.unrealengine.com/t/how-to-use-eqs-in-c/368003/1 "2016-08-23T12:47:25Z")

</div>

Hi. I was wondering what the ‘correct’ way to use EQS from C++ is. I saw the topic [https://answers.unrealengine.com/questions/438304/eqs-via-c.html](https://answers.unrealengine.com/questions/438304/eqs-via-c.html) but this didn’t help me very much.

If we’re meant to do it by creating an instance of FEnvQueryRequest, how do we pass in which query we wanted to do to it?

Going further than that, is there a sample of how to create queries in c++, and can we get the queries made in blueprint for c++, like how you do it with ConstructorHelpers for bp classes?

Thanks!

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_593961aa1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_593961aa1](https://forums.unrealengine.com/u/anonymous_user_593961aa1)\
**Post date:** [October 16, 2016, 4:28am UTC](https://forums.unrealengine.com/t/how-to-use-eqs-in-c/368003/2 "2016-10-16T04:28:59Z")

</div>

I would also like to see a sample of this.

---

<div class="post-metadata">

**Author:** ![PasteDog](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@PasteDog](https://forums.unrealengine.com/u/PasteDog)\
**Post date:** [October 16, 2016, 3:36pm UTC](https://forums.unrealengine.com/t/how-to-use-eqs-in-c/368003/3 "2016-10-16T15:36:15Z")

</div>

Hey Xavice,

I’ll give you an example how to use the EQS system in c++, MyActor is the class:  
In MyActor.h

```
UPROPERTY()
UEnvQuery* MyQuery; // set the query in editor
FEnvQueryRequest * MyQueryRequest;
// The function that gets called when querry finished
void MyQueryFinished(TSharedPtr<FEnvQueryResult> Result);

```

In MyActor.cpp

```
void MyActor::BeginPlay()
{
	MyQueryRequest = FEnvQueryRequest(MyQuery, this);
}

void MyActor::RunEQS()
{
	MyQueryRequest.Execute(EEnvQueryRunMode::SingleResult, this, MyActor::MyQueryFinished);
}

void MyActor::MyQueryFinished(TSharedPtr<FEnvQueryResult> Result)
{
	AActor* result = Result->GetItemAsActor(0);
	//...
}

```

If you need any more information you can ask!

Hope this helps 🙂  
Elias

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_593961aa1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_593961aa1](https://forums.unrealengine.com/u/anonymous_user_593961aa1)\
**Post date:** [October 16, 2016, 9:53pm UTC](https://forums.unrealengine.com/t/how-to-use-eqs-in-c/368003/4 "2016-10-16T21:53:09Z")

</div>

Thanks, excuse my ignorance I am new to EQS, but if MyQuery refers to a Test, where is the Generator set/created?

---

<div class="post-metadata">

**Author:** ![PasteDog](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@PasteDog](https://forums.unrealengine.com/u/PasteDog)\
**Post date:** [October 17, 2016, 7:47am UTC](https://forums.unrealengine.com/t/how-to-use-eqs-in-c/368003/5 "2016-10-17T07:47:55Z")

</div>

You create your EQS in the editor like any other EQS you would run in the behavior tree, and then set it in Blueprints 🙂

---

<div class="post-metadata">

**Author:** ![Xavice](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Xavice](https://forums.unrealengine.com/u/Xavice)\
**Post date:** [November 4, 2016, 1:44am UTC](https://forums.unrealengine.com/t/how-to-use-eqs-in-c/368003/6 "2016-11-04T01:44:42Z")

</div>

Thanks that helped. I was trying to find a way to make or get the queries from c++ rather than just feeding them in through BP, but this’ll work just fine too.

---

<div class="post-metadata">

**Author:** ![Raz1789](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Raz1789](https://forums.unrealengine.com/u/Raz1789)\
**Post date:** [April 29, 2019, 4:08pm UTC](https://forums.unrealengine.com/t/how-to-use-eqs-in-c/368003/7 "2019-04-29T16:08:42Z")

</div>

I think there is an “&” missing in line 8 of the code for function address. So the line would be:

MyQueryRequest.Execute(EEnvQueryRunMode::SingleResult, this, &MyActor::MyQueryFinished);

---

<div class="post-metadata">

**Author:** ![Bitwaker](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Bitwaker](https://forums.unrealengine.com/u/Bitwaker)\
**Post date:** [May 21, 2019, 5:25pm UTC](https://forums.unrealengine.com/t/how-to-use-eqs-in-c/368003/8 "2019-05-21T17:25:41Z")

</div>

I’ve just written an article about the topic 🙂

> **[Unreal Engine: Environment Query System (EQS) in C++](https://www.thinkandbuild.it/environment-query-system-in-c/)**
>
> I’m still working at the AI system for The Mirror’s End and I decided to move the entire AI core from Behavior Tree to Utility AI. Environment Query System (EQS) is very well integrated with Behavior Trees and I really didn’t want to loose the...

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_a3a170d9](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_a3a170d9](https://forums.unrealengine.com/u/anonymous_user_a3a170d9)\
**Post date:** [January 26, 2021, 2:15pm UTC](https://forums.unrealengine.com/t/how-to-use-eqs-in-c/368003/9 "2021-01-26T14:15:10Z")

</div>

PasteDog - Have you ever tried to create Async EQS generators/tests?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_4b9de05d](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_4b9de05d](https://forums.unrealengine.com/u/anonymous_user_4b9de05d)\
**Post date:** [September 16, 2021, 1:15am UTC](https://forums.unrealengine.com/t/how-to-use-eqs-in-c/368003/10 "2021-09-16T01:15:47Z")

</div>

The syntax here is wrong. Please edit your solution. @PasteDog

---

<div class="post-metadata">

**Author:** ![Vahid](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Vahid](https://forums.unrealengine.com/u/Vahid)\
**Post date:** [January 11, 2023, 7:26pm UTC](https://forums.unrealengine.com/t/how-to-use-eqs-in-c/368003/11 "2023-01-11T19:26:55Z")

</div>

Hello,  
Sorry for sending message in an old topic.  
I need some help to send a vector value into my EQS from C++  
I have a custom AI logic and I just need to some check from EQS, I made my EQS and it works properly with test data but I need a way to pass some game data into EQS from the C++.  
Thank you

---

<div class="post-metadata">

**Author:** ![Lorelands](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Lorelands](https://forums.unrealengine.com/u/Lorelands)\
**Post date:** [April 9, 2025, 2:25pm UTC](https://forums.unrealengine.com/t/how-to-use-eqs-in-c/368003/12 "2025-04-09T14:25:43Z")

</div>

For anyone who stumbles here with the error:

`Unable to find 'class', 'delegate', 'enum', or 'struct' with name 'TSharedPtr'`

Make sure that your callback function is _NOT_ marked with `UFUNCTION()` 🙂

---

<div class="post-metadata">

**Author:** ![emperor\_katax](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/emperor_katax/32/1070178_2.png) [@emperor\_katax](https://forums.unrealengine.com/u/emperor_katax)\
**Post date:** [September 24, 2026, 11:55am UTC](https://forums.unrealengine.com/t/how-to-use-eqs-in-c/368003/13 "2026-09-24T11:55:02Z")

</div>

Link is not working.
