Skip to content

Navmesh Link

Updated

A shortcut between two points: a jump, ladder or teleport.

Type
ent-navmesh-link
Script class
NavMeshLinkEntity

A NavMesh Link is a shortcut on the navmesh: it joins two points that the walkable surface does not otherwise connect, such as a gap to jump, a ledge to drop from or a ladder. The link entity’s own position is the start, and its end prop is the far end, as an offset from it. Rotating the entity turns the whole link. In the editor it shows as an arc with arrowheads, a jump icon and a ring at each end; you drag the far end with the move gizmo.

Links are baked into the NavMesh Surface, like the rest of the navmesh. A character following a path that uses a link walks to its entry, jumps across along the arc, and carries on to its destination. While it crosses, its NavMesh Agent’s isGrounded is false, and a Character Controller on it reports the jump state.

Use a link whenever characters must cross a place where there is no continuous floor. Characters on a navmesh have no gravity and cannot jump on their own: without a link, a gap is simply a wall.

The props that matter most:

  • end is the far end, as an { x, y, z } offset in the link entity’s local space.
  • bidirectional: true lets characters cross both ways; false only from the start to the end, which suits a drop they cannot climb back up.
  • arcHeight is the peak height of the jump, in metres. 0 is a flat crossing.
  • radius is the capture radius at each end, in metres: how close a character must come to an end to be taken onto the link. It is not the width of the link.
  1. Make sure the scene has a NavMesh Surface and that both sides have walkable, baked ground.
  2. Add a NavMesh Link entity and place it on the ground at the start of the crossing. See Scenes and hierarchy.
  3. Drag its far end, or set end, so it rests on the ground on the other side.
  4. Set bidirectional and arcHeight for the kind of crossing: a two-way jump, or a one-way drop.
  5. Select the NavMesh Surface and bake again. A link takes effect only once it is baked in.

Remove a jump from the navmesh when a bridge is raised, and put it back when it is lowered.

Drawbridge.jx
#pragma lifecycle(startup)
function startup() {
const link = findEntity('Bridge Link');
const surface = findEntity('NavMesh Surface').getComponent(NavMeshSurfaceComponent);
async function setOpen(open) {
link.setEnabled(open);
const ok = await surface.bake();
log(open ? 'Bridge lowered' : 'Bridge raised', ok ? '' : '(bake failed)');
emit('bridge/changed', { open });
}
on('bridge/raise', () => setOpen(false));
on('bridge/lower', () => setOpen(true));
}

How it works:

  • setEnabled(false) switches the link entity off; switching it changes what the surface bakes, so the old navmesh no longer matches.
  • bake() rebuilds the navmesh from the current geometry and the links that are on. It returns a promise of true on success, which the async function awaits.
  • Characters plan their next paths on the new navmesh, so they take the long way round while the bridge is up.

Notice when a character starts and ends a link crossing, and tell its animation script.

LinkJumpCue.jx
#pragma lifecycle(startup, update)
let agent;
let wasGrounded = true;
function startup() {
// This Behavior sits under a character with a NavMesh Agent.
agent = self.parent.getComponent(NavMeshAgentComponent);
}
function update() {
if (!agent) return;
const grounded = agent.isGrounded;
if (grounded === wasGrounded) return;
wasGrounded = grounded;
emit(grounded ? 'hero/land' : 'hero/jump');
}

How it works:

  • A NavMesh Agent’s isGrounded is false only while it crosses a link, so its change marks the start and the end of the jump.
  • The script remembers the last value and emits only when it changes, not every frame.
  • With a Character Controller on the character, you can instead listen to its EventType.CharacterController.StateChange event, whose data.state is jump while it crosses.

Turn a two-way jump into a one-way drop at runtime, for example after a ladder breaks.

BrokenLadder.jx
#pragma lifecycle(startup)
function startup() {
const link = findEntity('Ladder Link').getComponent(NavMeshLinkComponent);
const surface = findEntity('NavMesh Surface').getComponent(NavMeshSurfaceComponent);
on('ladder/broken', async () => {
link.setProps({ bidirectional: false, arcHeight: 0 });
if (await surface.bake()) log('The ladder only goes down now');
});
}

How it works:

  • getComponent(NavMeshLinkComponent) reaches the link’s settings.
  • bidirectional: false allows crossing from the start to the end only; arcHeight: 0 makes the crossing a straight drop instead of a jump.
  • Any change to a link needs a new bake before characters use it.
  • Put both ends on baked ground. An end that floats in the air or sits inside an obstacle is never reached, however large its radius.
  • Moving or editing a link clears the surface’s baked data. Bake again in the editor before you publish.
  • Use bidirectional: false for drops: characters can then go down but never try to jump back up.

What a new Navmesh Link is made of. Required components are always present and cannot be removed; the others can. Per entity says whether an entity can hold one of that component or several. Layer, Lock and Enable are on every placed entity, and Transform holds its position, rotation and scale.

Component Type Role Per entity What it does
Layer comp-layer Required One Puts the entity on a render/raycast layer so cameras and rays can include or skip it.
Lock comp-lock Required One Editor-only flag that stops the entity from being selected or moved.
Enable comp-enable Required One Turns the entity and its children on or off: hides them and stops their behavior.
Transform comp-transform Required One Position, rotation and scale of the entity, with optional editor-only per-axis locks.
Navmesh Link comp-navmesh-link Required One A shortcut between two points: a jump, ladder or teleport.

You can also add 1 optional components, such as Signal Emitter.

The settings of a new entity, as the runtime creates it. Change them in the Properties panel of XR Creator, or from a script with getComponent(…).setProps({ … }).

Prop Default Range
end {"x":0,"y":0,"z":2}
radius 0.5 0.001 ≤ x ≤ 10
bidirectional true
arcHeight 1.2 0 ≤ x ≤ 10

With a Signal Emitter on the entity, these events reach scripts as { entityId, eventType, data }. Compare eventType with the EventType constants.

It reports the events every entity has: Transform::change (and position-change, rotation-change, scale-change), Enable::change, Layer::change and Lock::change.

Run it in the browser, read its scripts, and download it as an XR Creator project.

Find the entity by its name, check its class, and work with its components. Name the entity in the Hierarchy first; this example expects My Navmesh Link.

NavMeshLinkEntity.jx
#pragma lifecycle(startup)
function startup() {
// Find the entity by the name it has in the Hierarchy.
const entity = findEntity('My Navmesh Link');
if (!(entity instanceof NavMeshLinkEntity)) return;
// Its Navmesh Link component holds the settings listed under Props.
const component = entity.getComponent(NavMeshLinkComponent);
log('radius is', component.props.radius);
component.setProps({ radius: 0.75 });
}