Using Unity’s NavMesh for Navigation with Area Targets

Use Area Targets to navigate your users in large spaces. Integrate Unity’s navigation system to map your model or point cloud and create navigation between the user and points of interest (POI) in your AR application.

Prerequisites

A unity project with an Area Target and an AR Camera in the scene. See Area Targets in Unity for setup instructions.

The imported AI Navigation package from the Package Manager.

Area Targets and NavMesh

Follow these steps to set up a NavMesh surface and NavMesh agent.

Your imported Area Target will appear as a textured mesh or a point cloud. The steps to add a NavMesh surface differ slightly between the two.

  1. Set the ARCamera's World Center Modeto FIRST_TARGET if you are using a single Area Target or specify an Area Target as SPECIFIC_TARGET to center the world origin around it.

Setting the mode to DEVICE may offset the NavMesh agents' positioning at runtime. See Spatial Frame of Reference on how to change the mode.

Area Target mesh

  1. Select the Area Target GameObject, click Add Component, and select Navigation -> NavMeshSurface.
  2. Click Bake. A blue overlay should appear on the surface.

Area Target point cloud

  1. Right-click the Hierarchy and select AI -> NavMesh Surface. Add it as a child of the Area Target GameObject.
  2. Add the navmesh.prefab as a child of the Area Target. It is found under Assets/Editor/Vuforia/<YourAreaTarget>. Position it to match the Area Target GameObject.
  3. Click Bake in the NavMesh Surface’s component.
  4. Deactivate the NavMesh prefab until you need to update the NavMesh by clicking Bake The NavMesh prefab can be deleted as the NavMesh is saved as an asset.

Adjust the NavMesh Surface

Depending on your scanned space, adjustments may need to be made to cover the Area Target space correctly. In the navigation panel, adjust the baking settings for agents.

NavMeshes and agent types are tied together so that multiple agents and surfaces with different settings can be used on the same surface.

  1. Go to Window -> AI -> Navigation. The new panel allows you to create agents and adjust agent parameters. The Areas tab allows you to add costs to specified areas.
  2. Make sure the correct agent type is selected. Adjust your agent's radius, height, and step height to increase or decrease the walkable surface.
  3. Update the NavMesh by returning to the NavMeshSurface component and click Bake.
    NOTE: If gaps between the overlay around doorways still exist, edit the step heights to include more walkable areas in your scanned space. Proceed to click Bake again for an updated overlay.

Removing areas from the NavMesh

Use the NavMesh Modifier component on existing GameObjects or the NavMesh Modifier Volume to mark the areas you wish to remove from the NavMesh surface.

  1. Right-click in the Hierarchy and select AI -> Navmesh Modifier Volume.
  2. Adjust the box size and placement for the area you wish to remove as walkable.
  3. Click Bake to update the NavMesh.

See also Navigation Areas and Costs to change and improve pathing and the walkable navigation area.

Add NavMesh Navigation

Add pathing between two points by creating destination points. Unity automatically calculates the shortest path between the two points. Add obstacles and modifiers to improve the pathing, as the image below shows.

Use the transforms of GameObjects for destination points. In most cases, the AR Camera represents the user and acts as the player. Use the Line Renderer component to render a line between the destination point and the user. See the NavMeshManager class in the Vuforia Core Samples for an example that uses the line renderer.

Continue to edit the NavMesh for your use case, add points of interest in your scene, and guide users between points. Use NavMesh obstacles to create blockades or restrictions to navigation.

Return to Unity’s manual to learn more about the applications of using NavMesh as navigation.

Can this page be better?
Share your feedback via our issue tracker