A navigation mesh, or navmesh, is a simplified representation of a game level made of connected convex polygons that mark where AI-controlled characters can walk. In game engines, it is the standard data structure for pathfinding: agents search a route across the polygons and then move along it while avoiding obstacles and each other.
The navmesh is separate from the visible geometry and from the collision used by the physics engine. It is a purpose-built map for movement, generated from level geometry and the physical dimensions of an agent, and it trades exact detail for fast, reliable route queries at runtime.
How a navigation mesh represents walkable space
Each polygon in a navmesh is convex, which guarantees that an agent can travel in a straight line between any two points inside it without leaving walkable space. Polygons share edges called portals, and the connections between them form a graph that search algorithms can traverse quickly.
The mesh is usually shrunk by the agent radius so that the center point of a character can move anywhere on it without its body clipping into walls. This is why a single level often needs separate navmeshes for different agent sizes, such as a human soldier and a large vehicle.
Most engines generate the navmesh automatically from level geometry. The widely used voxel-based pipeline, popularized by the open-source Recast library, works in the stages shown below.
| Stage | What happens | Result |
|---|---|---|
| Voxelization | Level geometry is rasterized into a grid of small cells | Solid heightfield |
| Walkability filtering | Cells are tested against slope, clearance and step height | Walkable spans only |
| Region building | Connected walkable areas are partitioned | Simple regions without holes |
| Contour tracing | Region borders are traced and simplified | Outline polygons |
| Polygon mesh | Outlines are split into convex polygons | Navigation polygons |
| Detail mesh | Height samples are added for uneven ground | Accurate surface height |
Key navmesh parameters and their effects
Generation is driven by agent parameters, and choosing them correctly is the most important step in setting up navigation. Wrong values produce gaps in doorways, agents climbing walls or meshes that take too long to build.
| Parameter | Typical range | What it controls |
|---|---|---|
| Agent radius | 0.3 to 0.6 m for humanoids | Distance kept from walls and edges |
| Agent height | 1.8 to 2.0 m for humanoids | Minimum ceiling clearance |
| Max slope | 30 to 50 degrees | Steepest surface treated as walkable |
| Step height | 0.3 to 0.5 m | Ledges an agent can step onto |
| Cell size | About one third of agent radius | Precision versus build time and memory |
| Tile size | Engine and level dependent | Granularity of partial rebuilds |
The cell size trade-off is central: smaller cells capture narrow passages accurately but multiply memory use and build time. Large open worlds therefore use tiled navmeshes, which divide the level into independent tiles that can be streamed in or rebuilt individually.
Pathfinding and movement on the navmesh
Navigation on a navmesh happens in three layers. First, a graph search, almost always the A* algorithm, finds a sequence of polygons from start to goal. Second, a string-pulling step, commonly the funnel algorithm, converts that corridor into the shortest sequence of straight segments through the portals. Third, local steering moves the agent along the path frame by frame.
Local steering handles what the precomputed mesh cannot: other moving agents and temporary obstacles. Crowd systems use techniques such as reciprocal velocity obstacles to pick collision-free velocities, while doors, crates and vehicles can carve holes into the mesh at runtime or trigger a rebuild of the affected tiles.
- Area costs make some surfaces, such as water or mud, more expensive so that agents avoid them when a reasonable alternative exists.
- Off-mesh links connect separate polygons for jumps, ladders, teleporters and doors.
- Navigation queries also answer questions such as the nearest reachable point or whether a location is reachable at all.
Navigation mesh compared with other pathfinding representations
Before navmeshes became standard, games relied on waypoint graphs and grids. Each representation still has valid uses, and the choice depends on level shape, dimensionality and the number of agents.
| Representation | Strengths | Weaknesses | Typical use |
|---|---|---|---|
| Navigation mesh | Compact, natural paths, covers full area | Complex generation, harder dynamic updates | 3D action, open worlds, shooters |
| Waypoint graph | Simple, cheap, fully hand-controlled | Zig-zag paths, no coverage between nodes | Small or scripted levels |
| Grid | Trivial updates, easy to reason about | Memory heavy, blocky paths | Strategy and tile-based games |
| Flow field | Efficient for many agents with one goal | One field per destination | Large crowds and RTS armies |
Major engines ship navmesh systems as a built-in feature. Unreal Engine builds on the Recast and Detour libraries, Unity provides a navigation package with components for surfaces, agents and links, and Godot exposes a navigation server with region and agent nodes. Flying and swimming characters usually need volumetric navigation instead, since a navmesh describes surfaces only.
Common navmesh problems and how to fix them
Most navigation bugs seen by players trace back to a mismatch between the navmesh and the actual level. Engines provide a debug view that draws the mesh over the scene, and inspecting it is the fastest diagnostic step.
| Symptom | Likely cause | Fix |
|---|---|---|
| Agents cannot pass a doorway | Agent radius too large for the gap | Widen the gap or reduce radius |
| Agents walk through thin walls | Cell size too coarse | Reduce cell size locally or globally |
| Islands of mesh on rooftops | Unreachable surfaces generated | Exclude them with volumes or modifiers |
| Agents get stuck at moving objects | Mesh not updated at runtime | Use obstacle carving or tile rebuilds |
| Hitches when the level changes | Full rebuild on the main thread | Use tiled, asynchronous rebuilds |
A further limitation is that a navmesh only answers where an agent can stand, not where it should go. Tactical choices such as cover positions or flanking routes require additional AI layers on top, built for example with behavior trees or utility systems.
Stripped to the essentials
A navigation mesh is like a simplified floor plan that game characters use to find their way. The game marks every spot where a character can safely walk. It then splits that area into simple shapes that link together.
Suppose a character needs to reach a door. The game checks this plan and finds a short route through the connected shapes. Then it steers the character along that route and keeps it clear of others nearby.
Where it is applied
A small studio builds a third-person stealth game with guards that patrol a multi-story warehouse. The designers configure a humanoid agent with a 0.4 m radius, a 1.8 m height, a 45-degree maximum slope and a 0.4 m step height, then let the engine generate a tiled navmesh for the whole level.
Stairs and ramps connect automatically, while ladders and a jump between catwalks are added as off-mesh links. When the player knocks over shelving, the fallen objects carve the mesh so that guards route around them instead of walking into them.
During testing, the debug view reveals that one narrow corridor is missing from the mesh because the gap is smaller than twice the agent radius. Widening the corridor slightly fixes the issue, and guards now follow believable, efficient routes throughout the level.