PathForge — Getting Started
PathForge finds routes for your units on the map you already have — a Tilemap, a hex grid, waypoints, a triangle mesh or Unity’s baked NavMesh. Every route is the shortest one, it is the same on every run and platform, and nothing is allocated per query. PathForge tells your units which way to go; moving, animating and avoiding each other stays in your code.
Install
- Unity 6 (6000.0 or later), Mono or IL2CPP.
- Package Manager → My Assets → PathForge → Install.
- Sample scenes: Package Manager → PathForge → Samples → Import.
Let your coding assistant set it up
Paste one line into Claude Code, Codex, Cursor or any assistant that can read your project:
Read and execute Packages/com.birdblu.pathforge/Documentation~/pathforge-setup/SKILL.md
Online copy: https://birdblu.com/pathforge/pathforge-setup/SKILL.md. The assistant checks the
native plugin, picks the adapter for your map, writes the code and verifies one route.
PathForge Pro adds Documentation~/pathforge-pro-setup/SKILL.md for crowds.
The three-line start
var solver = new DnskSolver(builder.NumVertices); // builder: the adapter for your map
solver.BuildFrom(builder);
var path = solver.QueryPath(start, goal, buffer); // the route lands in your buffer
Build once, then ask for as many routes as you like. All PathForge types are in the global
namespace — no using needed.
Your first route, step by step
One enemy walks from A to B on a Tilemap.
1. Set up the grid. Create a Grid with a Tilemap (GameObject → 2D Object → Tilemap) and paint wall tiles where units must not walk.
2. Add this script to any GameObject and assign the references in the Inspector:
using UnityEngine;
using UnityEngine.Tilemaps;
public class MyPathfinding : MonoBehaviour
{
[SerializeField] private Grid grid;
[SerializeField] private Tilemap tilemap;
[SerializeField] private Transform enemy;
[SerializeField] private Transform target;
private const uint Cols = 20, Rows = 15; // your Tilemap size
private DnskSolver solver;
private GridGraphBuilder builder;
private readonly uint[] pathBuffer = new uint[Cols * Rows]; // reused for every query
void Start()
{
builder = new GridGraphBuilder(grid, tilemap, Cols, Rows); // tile = wall
solver = new DnskSolver(builder.NumVertices);
solver.BuildFrom(builder);
}
void Update()
{
if (!Input.GetMouseButtonDown(0)) return;
var result = solver.QueryPath(ToVertex(enemy.position), ToVertex(target.position), pathBuffer);
if (result.Reachable)
Debug.Log($"Route: {result.PathLength} cells, cost {result.Distance}");
// pathBuffer[0 .. PathLength-1] are the cells; builder.VertexToWorld(v) gives positions
else
Debug.Log("No route — the target is walled off");
}
void OnDestroy() => solver?.Dispose();
uint ToVertex(Vector3 p) =>
(uint)(Mathf.FloorToInt(p.x) + Mathf.FloorToInt(p.y) * (int)Cols);
}
What the pieces mean
- Vertex IDs. Every cell has a number:
x + y * Cols, counted row by row from the bottom-left cell.builder.VertexToWorld(v)turns a number back into a world position; turning a position into a number (ToVertex) is up to your game, because it depends on how you place units. - The buffer. You hand PathForge an array once and it writes every route into it — nothing
piles up for the garbage collector. Declare it as a field, never inside
Update(). A buffer ofCols * Rowsfits any route on the grid. - Dispose. The solver holds native memory: call
Dispose()inOnDestroy().
Pick the adapter for your map
| Your map | Adapter | Good to know |
|---|---|---|
| Grid + Tilemap, a tile is a wall | GridGraphBuilder |
diagonal: true for 8 directions |
| Tilemap, a tile is floor, terrain costs | TilemapGraphBuilder |
SetTileWeight(sandTile, 3) |
| Hex grid (pointy-top) | HexGraphBuilder |
blocked cells from a function |
| Waypoints you place | WaypointGraphBuilder |
connects points within a distance |
| Any triangle mesh | MeshGraphBuilder |
each triangle is a cell |
| Unity’s baked NavMesh | NavMeshGraphBuilder |
Polyline(route) gives the line to walk |
| Anything else | your own IGraphSource |
Bring Your Graph |
Every constructor and option: API Reference → Graph adapters.
Doors, walls and mud: dynamic maps
Change the built map at runtime — no rebuild, nothing for the garbage collector, and every route stays the shortest one.
| You want to | Call |
|---|---|
| Close / reopen a cell | solver.BlockVertex(v) / solver.UnblockVertex(v) |
| Make a move more expensive (mud), or cheaper again | solver.SetEdgeWeight(a, b, cost) |
| Close one direction (door, one-way gate) | solver.CloseEdge(a, b); reopen with SetEdgeWeight |
With the Grid, Tilemap and Hex builders, mark the cells that can change as dynamic cells; the builder then does the calls for you:
var builder = new GridGraphBuilder(grid, walls, cols, rows, diagonal: true,
dynamicCell: (x, y) => doorMap[x, y]); // doors and breakable walls
solver.BuildFrom(builder);
builder.ApplyDynamicCells(solver); // once: close the doors that are closed now
// Later, a door opens:
walls.SetTile(doorCell, null);
builder.RefreshCell(solver, doorX, doorY);
Three rules:
- Build the map with every cell that can ever be walkable, each at its lowest cost. Making a move cheaper than that, or adding new cells, needs a new solver.
- Cells that are not dynamic must not change after the build.
- PathForge Pro: compute fields again after a change — reading an old field throws
“field is stale”.
solver.GraphVersionchanges exactly when that is needed.
Details: API Reference → Dynamic maps rules.
Save once, load at startup
For a finished level, save the built map and skip the build at startup:
// In the editor, once:
File.WriteAllBytes(Path.Combine(Application.streamingAssetsPath, "level1.bin"), solver.SaveGraph());
// At runtime:
solver = new DnskSolver(numVertices);
solver.LoadGraph(File.ReadAllBytes(Path.Combine(Application.streamingAssetsPath, "level1.bin")));
A loaded map answers every query exactly like the one that was saved, including cells you had closed. See API Reference → Saving and loading.
Many agents, one goal: PathForge Pro
Units heading to their own goals: one QueryPath each, with Base — any number of them.
A crowd heading to the same goal, or the nearest of a few: compute one field with
PathForge Pro, and every agent reads its next step from it — all agents in one call per frame.
using PathForge.Pro;
var field = solver.CreateField();
field.ComputeField(baseVertex, distances); // once (again after a map change)
// every frame:
int valid = field.BatchNextStep(agentVertices, nextVertices, arrived);
Weighted target sets, routes along a field and the field cache: API Reference → DnskField. The six Pro sample scenes show complete games (Tower Defense, Nearest Exit, Colony Sim, Supply Run, Swarm Chase, Many Agents).
Next
- API Reference — every type and method, with errors.
- Bring Your Graph — your own graph structure.
- Troubleshooting — plugin loading, empty routes, common mistakes.
- FAQ — platforms, multiplayer, Base or Pro.
DnskPathFollower— a component that walks an agent along a route for you (API Reference).- Sample scenes — QuickStart, Benchmark, Determinism, Graph Gallery, Base Demo: Package Manager → PathForge → Samples → Import.