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"

How to use EQS in c++

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 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!

Product Version: UE 4.11
Tags:
more ▼

asked Aug 23 '16 at 12:47 PM in C++ Programming

avatar image

Xavice
15 3 4 7

avatar image bentwonk Oct 16 '16 at 04:28 AM

I would also like to see a sample of this.

avatar image Bitwaker May 21 '19 at 05:25 PM

I've just written an article about the topic :) https://www.thinkandbuild.it/environment-query-system-in-c/

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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

more ▼

answered Oct 16 '16 at 03:36 PM

avatar image

PasteDog
1.2k 24 18 53

avatar image bentwonk Oct 16 '16 at 09:53 PM

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

avatar image PasteDog Oct 17 '16 at 07:47 AM

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

avatar image Xavice Nov 04 '16 at 01:44 AM

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.

avatar image Raz1789 Apr 29 '19 at 04:08 PM

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);

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
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