Navigation meshes
Updated
A navmesh (navigation mesh) is a simplified map of every place a character can stand. It is baked from the surfaces you mark as walkable, and carved around the obstacles you mark as collidable. NavMesh Agents then find their paths across it, and NavMesh Links join the places it does not connect.
Before you start
Section titled “Before you start”- Navigation usually drives a Character Controller, which walks, turns and reports its state.
- Events reach scripts through a Signal Emitter on the entity.
How it fits together
Section titled “How it fits together”| Part | Where it goes | What it does |
|---|---|---|
| NavMesh Surface | A NavMesh Surface entity (ent-), one per scene |
Owns the navmesh, its bake settings and the crowd every agent moves in. |
| NavMesh Walkable | Floors, ramps, platforms: meshes, models, primitives, kit pieces, terrain, groups | Its surfaces become ground agents walk on. |
| NavMesh Collidable | Walls, crates, furniture | Its geometry is an obstacle the navmesh is carved around. |
| NavMesh Link | A NavMesh Link entity (ent-) |
A shortcut the surface does not otherwise join: a jump, a drop, a ladder. |
| NavMesh Agent | The moving character | Finds paths and moves across the navmesh. |
To set up navigation:
- Add a NavMesh Surface entity to the scene.
- Add NavMesh Walkable to the floors, ramps and platforms, and NavMesh Collidable to walls, crates and other obstacles.
- Select the surface in the editor to see the navmesh, and bake it.
- Add a NavMesh Agent to each character, usually with a Character Controller (
controls: falsefor non-player characters).
NavMesh Walkable and NavMesh Collidable also decide where a Teleport can land.
NavMesh Surface
Section titled “NavMesh Surface”NavMesh Surface (comp-navmesh-surface) is the scene’s walkable area. Once baked, it stores the navmesh in its data prop, so play loads it at once. Without baked data, play bakes the navmesh from the scene’s geometry when it is first needed, which costs time on load: bake in the editor before you publish. Only one surface is used across the active scenes.
Bake settings
Section titled “Bake settings”The most useful settings:
| Prop | Default | Description |
|---|---|---|
cellSize |
0.166 |
Horizontal resolution, in metres. Smaller cells follow edges more closely but take longer to bake. |
cellHeight |
0.1 |
Vertical resolution, in metres. |
agentHeight |
1.7 |
Headroom a character needs, in metres. Low ceilings are excluded. |
agentRadius |
0.5 |
Clearance kept from walls and edges, in metres. |
agentMaxClimb |
0.3 |
Tallest step a character climbs, in metres. |
agentMaxSlope |
45 |
Steepest walkable slope, in degrees. |
Advanced settings (regionMinSize, regionMergeSize, edgeMaxLen, edgeMaxError, vertsPerPoly, detailSampleDist, detailSampleMaxError) tune how the outline is simplified; the reference page lists them.
The bake reads every mesh under an entity with an enabled NavMesh Walkable or NavMesh Collidable. If nothing is marked, every visible mesh is used, so a first bake still gives something. Large scenes bake in tiles a little at a time, so neither the editor nor play freezes.
Scripting
Section titled “Scripting”| Member | What it does |
|---|---|
isReady |
Whether the navmesh and crowd are live. |
closest |
The nearest point on the navmesh to { x, y, z }, or undefined. |
compute |
The corners of a path between two world points; empty when unreachable. |
random |
A random reachable point within radius of center, or undefined. |
bake(on |
Bake a fresh navmesh from the current geometry. Returns a promise of true on success. onProgress receives 0 to 1. |
cancel() |
Stop a bake under way. |
reset() |
Clear the baked navmesh. |
NavMesh Walkable and NavMesh Collidable
Section titled “NavMesh Walkable and NavMesh Collidable”- NavMesh Walkable (
comp-navmesh-walkable, no props) marks its entity’s surfaces as ground. Surfaces steeper thanagentMaxSlopeor under a low ceiling are left out. On an entity with both markers, Walkable wins. - NavMesh Collidable (
comp-navmesh-collidable) marks its entity as an obstacle; its top is not walkable.
| NavMesh Collidable prop | Type | Default | Description |
|---|---|---|---|
padding |
number | 0 |
Extra clearance around the obstacle, in metres, on top of agentRadius. |
Examples
Section titled “Examples”1. Bake at runtime after building a level
Section titled “1. Bake at runtime after building a level”#pragma lifecycle(startup)
function startup() { // Another script builds the maze, then emits 'maze/built'. const surface = findEntity('NavMesh Surface').getComponent(NavMeshSurfaceComponent);
on('maze/built', async () => { emit('hud/toast', { text: 'Preparing paths…' }); const ok = await surface.bake((progress) => log(`Baking ${Math.round(progress * 100)}%`)); emit(ok ? 'maze/ready' : 'maze/failed'); });}A button raises maze/built and the script rebakes the NavMesh Surface from the walkable floor and collidable walls, logging the bake's progress.
Press Bake and watch the progress in the script log. Drag to orbit the camera, scroll to zoom.
When the geometry changes at runtime (a procedurally built maze, say), bake rebuilds the navmesh from it. It returns a promise that resolves true on success, so the async listener can await it and then emit maze/ready for the agents’ scripts to start moving. Baking a large area takes several frames but never freezes the game.
Common mistakes
Section titled “Common mistakes”- Agents walk through a wall. The wall needs NavMesh Collidable, and the navmesh needs a new bake after the change.
- Forgetting to bake. Without baked data, play bakes on load, which delays agents. Bake in the editor.