Using Navmesh Off Mesh Links
Unity Nav Mesh Links
scripts are baked into the Quantum navmesh (Quantum.NavMesh.Links
).
The following fields are used during baking:
Bidirectional
- creates two links in each directionCostModifier
- used as input forQuantum.NavMeshLink.CostOverride
Area Type
- set the region of the link (see Toggling a Navmesh Link at Run-Time section)Activated
- if not activated the link will be skipped during bakingGameObject.name
- used as input for QuantumQuantum.NavMeshLink.Name
Creating a Navmesh Link
- Create and configure a Unity
NavMesh Link
- Bake the Quantum navmesh and verify the link by checking the gizmos for blue arrows (Quantum gizmo overlay menu, enable
NavMeshLinks
and select theQuantumMapData
GameObject) - Agents now considers the link for path-finding.
Toggling a Navmesh Link at Run-Time
Links can be toggled on and off during runtime using Quantum navmesh regions. They can be baked with a region id and toggled globally or per agent. Read the Regions Manual for more information.
Simple Region Mode
Choose the Area Type
of the Unity NavMesh Link
to set the region.
Advanced Region Mode
- Set the
Area Type
of the UnityNavMesh Link
to a region detection area. - Attach a
MapNavMeshRegion
script to the UnityNavMesh Link
, set a regionId
and setCast Region
toNo Region
.

Customization and Signals
The link data structure can be queried from the navmesh asset using NavMesh.Links
. If a mapping from link index
to name
or vice-versa is required, a dictionary can be constructed.
The NavMeshPathfinder
component has the following Link API:
bool IsOnLink(FrameBase)
- returnstrue
when the agent is currently on a linkint CurrentLink(FrameBase)
- returns the current link index that points intoNavMesh.Links
or-1
when currently not on a link
Waypoint have link related WaypointFlags
:
LinkStart
- this waypoint is the start of a linkLinkStop
- this waypoint is the end of a linkRepathWhenReached
- after reaching this waypoint the agent re-runs path finding
When setting a new target while the agent is on a link the agent will finish the current link before executing the path-finding (see WaypointFlag.RepathWhenReached
).
No automatic re-pathing (for example for NavMeshAgentConfig.MaxRepathTimeout
) will be executed as long as the agent is traversing a link.
By default the agent will traverse the link with its normal speed.
To take control of the agent movement when the link has been reached, the ISignalOnNavMeshWaypointReached
signal can be used. Afterwards the agent can be disabled until an animation is complete or the movement can be overwritten in following ISignalOnNavMeshMoveAgent
callbacks.
- Receiving any navigation callbacks requires enabled
SimulationConfig.Navigation.EnabledNavigationCallbacks
- Receiving an
ISignalOnNavMeshMoveAgent
callback requires theNavMeshAgentConfig.MovementType
to be set toCallback
, it is possible to change the config of an agent at run-time.
The sample code performs a teleport when an agent steps on the link start waypoint.
C#
namespace Quantum
{
using Photon.Deterministic;
using UnityEngine.Scripting;
[Preserve]
public unsafe class NewQuantumSystem : SystemMainThread, ISignalOnNavMeshWaypointReached
{
public override void Update(Frame f)
{
}
public void OnNavMeshWaypointReached(Frame f, EntityRef entity, FPVector3 waypoint, Navigation.WaypointFlag waypointFlags, ref bool resetAgent)
{
var agent = f.Get<NavMeshPathfinder>(entity);
var waypointIndex = agent.WaypointIndex;
if ((waypointFlags & Navigation.WaypointFlag.LinkStart) == Navigation.WaypointFlag.LinkStart)
{
// There always is another waypoint after the LinkStart
var linkDestination = agent.GetWaypoint(f, waypointIndex + 1);
f.Unsafe.GetPointer<Transform2D>(entity)->Position = linkDestination.XZ;
}
}
}
}
Back to top