Sampling Positions using Apex Utility AI and Apex Path
This document is a part of a series of tutorial documents for getting started with the Apex Utility AI using Apex Path.
The purpose of this document is to provide a description to the classes used in the scene “AI_Demo_7”, as well as a tutorial on how to create a simple Apex Utility AI with the ability to scan for positions using Apex Path.
Sampling from the Apex Path Grid
Previously in AI Demo 4 the NavMesh was used for querying positions for walkability. The same can be achieved with Apex Path using very similar code. Thus, position sampling using the grid of Apex Path can be seen exemplified in the code snippet below.
public sealed class ApexPathPositionScanner : ActionBase<ApexPathPositionContext>
[ApexSerialization(defaultValue = 12f), FriendlyName("Sampling Range", "The range in which the Scanner will sample positions")]
public float samplingRange = 12f;
[ApexSerialization(defaultValue = 1.5f), FriendlyName("Sampling Density", "The density in which the Scanner will sample positions")]
public float samplingDensity = 1.5f;
// This will loop through all possible positions within the samplingRange and with a density equal to the samplingDensity
// Then check if that position is walkable or not, if it is we add it to the list of positions
public override void Execute(ApexPathPositionContext context)
var unitFacade = context.unitFacade;
var gridManager = GridManager.instance;
var position = context.unitFacade.position;
var halfSamplingRange = this.samplingRange * 0.5f;
for (float x = -halfSamplingRange; x <= halfSamplingRange; x += this.samplingDensity)
for (float z = -halfSamplingRange; z <= halfSamplingRange; z += this.samplingDensity)
var point = new Vector3(position.x + x, 0f, position.z + z);
var grid = gridManager.GetGrid(point);
if (grid == null)
var cell = grid.GetCell(point, false);
if (cell.isPermanentlyBlocked || !cell.IsWalkable(unitFacade.attributes))
As we did previously for AI Demo 4, we can use an Apex Utility AI Gizmo Visualizer for visualizing the sampled positions. The visualization code is virtually unchanged except for the type of context and action. A sphere is drawn using Unity Editor Gizmos for each sampled position, as can be seen in the screenshot below.