Average Reading Time: 3 minutes

In this post we’re going to create our own EQS Generator in Unreal Engine 4. This post assumes you’re familiar with the Environment Query System that resides in UE4. In case you don’t quite remember what this is, check out my previous post here.

Before we start creating our own Generator, check out the end result here:

This post was written in 4.13 version of UE4. In case you’re using a different version you may need to adjust the code in order to match with the corresponding API changes.

Download the source code from my github repo

Creating a custom EQS Generator

Our generator will create a cone in front of our AI pawn. Please note that in this case we won’t create a Pawn with custom behavior, instead, we’re going to use an EQS Testing Pawn. These Pawns help us test our EQS logic faster, since we don’t have to play or simulate our game.

Having said that, create a template project (it doesn’t matter if it’s C++ or Blueprint) and when the editor loads up activate the Environment Query System. In 4.13 version this option is located in the following path:

Edit -> Editor Preferences -> Experimental -> AI.

Here is a screenshot of the mentioned path:

enabling_eqs

Click on image to enlarge in a new tab

When you’re done with that, add a new C++ class named EnvQueryGenerator_Cone that inherits the EnvQueryGenerator_ProjectedPoints class. Then, inside its header file, type in the following code:

Then, inside the source file, implement the following logic for the GenerateItems function:

Notice that we didn’t call the Super::GenerateItems function. This is because this particular function is designed to be overriden completely. The default implementation should never be called, since it’s designed to throw an error.

Save and compile your code. Then:

  • Add a Nav mesh into your map
  • Create a Blueprint Pawn that inherits the EQSTestingPawn class
  • Place the EQSTestingPawn in your map

Then, create an Environment Query and call your C++ generator like the following screenshot suggests:

cone_eqs

When you’re done with that, assign the created EQS (ConeEQS in my case) to your placed EQSTesting Pawn:

eqstestingpawn

Click on image to enlarge in a new tab

Moreover, you should disable the Re Run Query Only on Finished Move for a more smooth display of your EQS while moving your Pawn.

At this point you have created your own generator! Temper with the values we exposed to the editor to have different results!

If you’ve made it this far, thank you!

Share postShare on Facebook32Tweet about this on TwitterShare on LinkedIn0Share on Reddit0