Spatial Query System

While designing smarter AI, the question that the systems in place have to answer often is: where should the entity go next? I found myself needing more than just hardcoded destinations or simple rules — I wanted a way to let agents make informed spatial decisions based on the environment around them given than most of the levels in the games I work on are procedurally generated. After some research, I was led to build the Spatial Query System.
It’s a modular, editor-friendly framework for evaluating and scoring points in space using a customizable stack of conditions (evaluators) like distance, visibility, and navigation cost. The tool is edit-mode friendly and runs smoothly on multiple agents simultaneously. This made the process of designing enemy AI easier and much more fun.

Role: Software Engineer
Game Engine: Unity
Programming Language: C#
Date:2025

Features

Core Framework

A framework for evaluating and return best points for AI agents to perform actions based on a set of evaluators. The package is compatible with Unity 2023 and above. It should work with older versions, but it hasn't been tested, and if anything breaks, it should be the editor side of things which I'm working on adding an option to disable.

Edit-mode support

The tool runs smoothly in the edit mode, which helps visualize the scoring process, debug, and fine-tune values without the agents' interference.

Customizable Debugger

Every aspect of how the system evaluates the score is debugged in edit and play mode, and the way it's all displayed is fully customizable through the editor.

Built-in Generators

Generators are components responsible for creating the sample points that will be evaluated. The system includes four commonly used types: Grid, Circular Grid, Ring, and Cone. Each generator offers configurable properties to control how and where points are placed. Custom generators can easily be added and will be recognized by the system without the need to do any referencing or values tweaking.

Evaluators

Evaluators are components responsible for scoring sample points based on given criteria. The framework has 5 built-in evaluators: Distance, Navmesh Distance, Direction (or angle), Line of Sight, and Overlap. Just like the generators, all the properties of the built-in evaluators are configurable and custom ones can be easily added and will be recognized by the system without having to do any referencing.

Scoring Weights, Filtering, and Priorities

In addition to scoring, each evaluator can be assigned a weight to control its influence. The system also supports filtering to exclude points based on specific conditions, reducing unnecessary processing. Evaluators can be prioritized to control the order in which they’re applied.

Sample Points Reports

For more in-depth debugging, the system provides scoring reports that can be viewed directly on each sample point's GameObject, allowing you to trace how every score was calculated over time.

Custom Components

As mentioned earlier, you can create custom generators, evaluators, and even evaluator subjects—transforms used by certain evaluators (like a target for distance checks)—using built-in templates available directly from the Unity menu.

More on how to do so on the project's GitHub page.

Back to Projects