How to use EQS in c++

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 :slight_smile:
Elias

5 Likes