Grid Pathfinding for Unity
A small pathfinding library for Unity 6, written from scratch: a grid graph, A* search, path simplification, an agent that walks the paths, and graph updates while the game runs.
What you get
- A grid that builds itself from your scene. Square, isometric or hexagonal cells, on the ground (XZ) or on the 2D plane (XY), turned with the object it sits on. Each cell is tested against your colliders for an agent of your size; heights, slopes and steps are read from the ground. In 2D it reads 2D colliders and tilemap colliders. Scan when the scene starts, on demand, or in the Editor.
- Fast A* search. Costs per cell, 32 tags that a unit can avoid or pay extra for, a choice of search estimate, paths to the nearest reachable cell when the goal cannot be reached, the nearest of several goals, and quick questions: can I get there, which cells are within N moves, a random walk, a way away from a threat.
- Smooth paths. Corners cut by line of sight, then rounded, relaxed or curved (Catmull-Rom or Bezier), or your own modifier.
- No frame spikes. Searches run on worker threads and the answer comes back on the main thread, as a callback
or with
await; or on the main thread within a time budget per frame. The search kernel is compiled by Burst and a plain search allocates nothing once warm. - A world that changes. Update a region when something moves, or let a Grid Obstacle do it; agents take a new path.
- Path Agent for characters that move freely: walks the path at its speed, turns, accelerates and brakes if you want, wanders and flees, and drives a transform, a CharacterController, a Rigidbody or a Rigidbody2D. Switch on Avoid Others and agents steer round each other and round walls.
- Tile Agent and Tile Crowd for units that move cell by cell (roguelikes, tower defence, colony and factory games): no two units share a cell or swap places, they take turns at doorways where there is room, slow units take several ticks per step, and turn-based games step the whole crowd by hand.
- Patrol Route and Orbit Route, several grids in one scene, and a plain C# core you can use without any component.
- Seven samples and a full manual, with a quick start for 2D and for 3D.
What it does not do
- No navmesh. It is a grid package. For navmeshes use Unity’s AI Navigation package.
- Avoidance is simple. Path Agents with Avoid Others on avoid each other and walls, nothing else (not other objects, not Tile Agents). It works on square grids (and isometric grids at a 1:1 aspect), not on hexagons. Bodies can overlap for a moment, and a large crowd sent to one point may not all settle. For hundreds of units, use Tile Agents.
- One floor per grid. Each cell has one height, so a grid cannot hold a bridge and the path under it.
- No ladders, jumps or teleporters on the grid. (A graph of your own nodes and links can hold them, from script.)
- A 2D grid is scanned from colliders, not from a tilemap’s tile data.
- The grid is not saved. It is rebuilt when the scene starts.
- One agent size per grid. For units of another size, add a grid for that size.
- Simple steering. No turning radius and no root motion.
- Tile Agents and Path Agents do not see each other: pick one kind for the units that must keep out of each other’s way.
Requirements
Unity 6.3 LTS or newer. Burst is optional; the search kernel uses it when it is installed.
Availability
The package is not released yet. Write to [email protected] if you want to hear when it is.