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
| Component | Description | Example |
|---|---|---|
| Generator | Creates candidate locations to test | Grid around querier, points on circle, actors of class |
| Context | Reference point for generators and tests | Querier (self), target enemy, all allies |
| Test | Scores or filters candidates | Distance, 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
| Test | Purpose | Scoring |
|---|---|---|
| Distance | Score based on distance to a context | Prefer closer or farther positions |
| Trace | Line-of-sight check between item and context | Filter: has/lacks LOS to enemy |
| Pathfinding | Check if location is reachable via NavMesh | Filter unreachable or prefer shorter paths |
| Dot Product | Directional preference (facing direction) | Prefer positions behind or in front of target |
| GameplayTag | Check tags on generated actors | Filter by actor properties |
Example: Find Cover Position
A typical "find cover" query works like this:
Generate Grid
Create a grid of points (spacing 100, radius 1500) around the AI character.
Filter Reachable
Pathfinding test removes points the AI cannot reach via the NavMesh.
Filter No LOS to Enemy
Trace test removes points where the enemy has direct line of sight (these are not cover).
Score by Distance
Prefer positions closer to the AI's current location (do not run across the map for cover).
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.
Lilly Tech Systems