Navigation mesh

Also known as: navmesh

On this page 7

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.

StageWhat happensResult
VoxelizationLevel geometry is rasterized into a grid of small cellsSolid heightfield
Walkability filteringCells are tested against slope, clearance and step heightWalkable spans only
Region buildingConnected walkable areas are partitionedSimple regions without holes
Contour tracingRegion borders are traced and simplifiedOutline polygons
Polygon meshOutlines are split into convex polygonsNavigation polygons
Detail meshHeight samples are added for uneven groundAccurate surface height
Typical stages of navmesh generation

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.

ParameterTypical rangeWhat it controls
Agent radius0.3 to 0.6 m for humanoidsDistance kept from walls and edges
Agent height1.8 to 2.0 m for humanoidsMinimum ceiling clearance
Max slope30 to 50 degreesSteepest surface treated as walkable
Step height0.3 to 0.5 mLedges an agent can step onto
Cell sizeAbout one third of agent radiusPrecision versus build time and memory
Tile sizeEngine and level dependentGranularity of partial rebuilds
Common navmesh generation parameters

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.

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.

RepresentationStrengthsWeaknessesTypical use
Navigation meshCompact, natural paths, covers full areaComplex generation, harder dynamic updates3D action, open worlds, shooters
Waypoint graphSimple, cheap, fully hand-controlledZig-zag paths, no coverage between nodesSmall or scripted levels
GridTrivial updates, easy to reason aboutMemory heavy, blocky pathsStrategy and tile-based games
Flow fieldEfficient for many agents with one goalOne field per destinationLarge crowds and RTS armies
Pathfinding representations in game engines

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.

SymptomLikely causeFix
Agents cannot pass a doorwayAgent radius too large for the gapWiden the gap or reduce radius
Agents walk through thin wallsCell size too coarseReduce cell size locally or globally
Islands of mesh on rooftopsUnreachable surfaces generatedExclude them with volumes or modifiers
Agents get stuck at moving objectsMesh not updated at runtimeUse obstacle carving or tile rebuilds
Hitches when the level changesFull rebuild on the main threadUse tiled, asynchronous rebuilds
Navmesh symptoms, causes and fixes

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.