Intermediate

Environment Query System (EQS)

EQS enables AI to ask spatial questions about the environment — "Where should I take cover?" "What is the best flanking position?" "Where should I patrol next?"

How EQS Works

The Environment Query System works in three steps: generate candidate locations, run tests to score each location, and return the best-scoring result. This is fundamentally different from behavior trees — EQS answers "where" questions while BTs answer "what to do" questions.

EQS Components

ComponentDescriptionExample
GeneratorCreates candidate locations to testGrid around querier, points on circle, actors of class
ContextReference point for generators and testsQuerier (self), target enemy, all allies
TestScores or filters candidatesDistance, trace (line of sight), pathfinding, dot product

Built-in Generators

  • Points: Grid: Generates a grid of points around a context. Most versatile generator for cover, positions, and areas.
  • Points: Circle: Generates points in a ring. Good for surrounding or flanking queries.
  • Points: Donut: Ring with inner and outer radius. Useful for maintaining distance ranges.
  • Actors Of Class: Returns all actors of a specified class. Perfect for finding items, allies, or objectives.
  • Current Location: Returns the querier's current position. Used to evaluate whether to stay put.

Common Tests

TestPurposeScoring
DistanceScore based on distance to a contextPrefer closer or farther positions
TraceLine-of-sight check between item and contextFilter: has/lacks LOS to enemy
PathfindingCheck if location is reachable via NavMeshFilter unreachable or prefer shorter paths
Dot ProductDirectional preference (facing direction)Prefer positions behind or in front of target
GameplayTagCheck tags on generated actorsFilter by actor properties

Example: Find Cover Position

A typical "find cover" query works like this:

  1. Generate Grid

    Create a grid of points (spacing 100, radius 1500) around the AI character.

  2. Filter Reachable

    Pathfinding test removes points the AI cannot reach via the NavMesh.

  3. Filter No LOS to Enemy

    Trace test removes points where the enemy has direct line of sight (these are not cover).

  4. Score by Distance

    Prefer positions closer to the AI's current location (do not run across the map for cover).

  5. Return Best

    The highest-scoring position becomes the cover destination, written to the Blackboard.

Using EQS in Behavior Trees

The Run EQS Query task node lets you execute an EQS query from within a behavior tree. The result is written to a Blackboard key that subsequent tasks (like Move To) can use.

Key takeaway: EQS is Unreal's system for spatial AI reasoning. It generates candidate positions, scores them with configurable tests, and returns the best option. Combine EQS with behavior trees for AI that intelligently chooses where to go based on the environment.