Skip to content

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.

  • Navigation usually drives a Character Controller, which walks, turns and reports its state.
  • Events reach scripts through a Signal Emitter on the entity.
Part Where it goes What it does
NavMesh Surface A NavMesh Surface entity (ent-navmesh-surface), 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-navmesh-link) 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:

  1. Add a NavMesh Surface entity to the scene.
  2. Add NavMesh Walkable to the floors, ramps and platforms, and NavMesh Collidable to walls, crates and other obstacles.
  3. Select the surface in the editor to see the navmesh, and bake it.
  4. Add a NavMesh Agent to each character, usually with a Character Controller (controls: false for non-player characters).

NavMesh Walkable and NavMesh Collidable also decide where a Teleport can land.

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.

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.

Member What it does
isReady Whether the navmesh and crowd are live.
closestPoint(point) The nearest point on the navmesh to { x, y, z }, or undefined.
computePath(from, to) The corners of a path between two world points; empty when unreachable.
randomPointAround(center, radius) A random reachable point within radius of center, or undefined.
bake(onProgress?) 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 (comp-navmesh-walkable, no props) marks its entity’s surfaces as ground. Surfaces steeper than agentMaxSlope or 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.
RuntimeBake.jx
#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');
});
}

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.

  • 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.