Basic Navigation

This guide shows how to use the Navigation System in Unreal Engine.

Choose your operating system:

Windows

macOS

Linux

Overview

The Unreal Engine Navigation System provides pathfinding capabilities to Artificial Intelligence Agents.

To make it possible to find a path between a start location and a destination, a Navigation Mesh is generated from the world's collision geometry. This simplified polygon mesh represents the navigable space in the Level. Default settings subdivide the Navigation Mesh into tiles to allow rebuilding localized parts of the Navigation Mesh.

The resulting mesh is made of polygons and a cost is associated with each polygon. While searching for a path, the pathfinding algorithm will attempt to find an optimal path with the lowest cost to the destination.

The system includes a variety of features that you can use to customize the Agent's navigation behavior based on your specific needs.

Goals

In this Quick Start guide, you will learn how to create a simple Agent that will use the Navigation System to roam around the Level.

Objectives

  • Use a Navigation Mesh Actor in your Level to build the navigation.

  • Learn to visualize the navigation mesh in your Level and adjust it to cover your needs.

  • Modify the ThirdPersonCharacter Blueprint to roam around the Level using the Navigation System.

1 - Required Setup

  1. In the New Project Categories section of the Unreal Project Browser, select Games and click Next .

    Select the Games category and click Next

  2. Select the Third Person template and click Next .

    Select the Third Person template and click Next

  3. Select the Blueprint and No Starter Content options and click Create Project .

    Select Blueprint and No Starter Content and click Create Project

Section Results

You have created a new Third Person project and are now ready to learn about the Navigation System.

2 - Building the Navigation Mesh

In this section you will use a Navigation Mesh Bounds Volume to specify the area in your Level where navigation needs to be generated. This information is used by Agents to navigate the Level and get to their destinations.

  1. On the default ThirdPersonExampleMap of your project, go to the Place Actors panel, search for Nav Mesh Bounds Volume, and drag it into your Level.

    Drag a Nav Mesh Bounds Volume actor to the Level

  2. With the Nav Mesh Bounds Volume selected, go to the Details panel and scale the volume to X = 20, Y= 20, and Z = 5. Move the volume so it covers the entire play area, as seen below.

    Scale the volume to X = 20, Y= 20, and Z = 5

    The volume now covers the entire play area

  3. Select the ThirdPersonCharacter Blueprint in the World Outliner window and remove it from the Level.

    Remove the Third Person Character from the Level

  4. Press the P key on your keyboard to visualize the Navigation Mesh in your Level. As you can see from the image below, the Navigation Mesh is visualized with the color green by default.

    Unreal Engine generates the Navigation Mesh automatically as soon as a Nav Mesh Bounds Volume Actor is added to the Level or is resized.

    Press P to visualize the Navigation Mesh

  5. Notice how the Navigation Mesh contains visual artifacts on the stairs. This can happen because the Navigation Mesh is a simplified representation of the collision in the Level. Select the RecastNavMesh-Default Actor in the World Outliner window and go to the Details panel. Go to the Display section and set the Draw Offset value to 50 . This adjusts the height offset where the Navigation Mesh is drawn for better readability.

    Set the Draw Offset to 50 for better readibility

Section Results

In this section you added a Nav Mesh Bounds Volume Actor to your Level and scaled it to fit the play area. You also learned how to visualize the final Navigation Mesh by pressing the P key.

3 - Visualizing the Navigation Mesh

In this section you will learn how to modify various Navigation Mesh settings, as well as how to change the way you can visualize the mesh in the Level.

  1. Go to the World Outliner and select the RecastNavMesh-Default Actor.

    Select the Recast Nav Mesh Actor Default from the World Outliner

  2. With the Actor selected, go to the Details panel and scroll down to the Display section. Here you will find a variety of options to better visualize the generated Navigation Mesh. In the example below, I selected the Draw Poly Edges to see the polygons that make up the mesh.

    Select Draw Poly Edges to see the polygons that make up the mesh

  3. You can also visualize the individual Navigation Tiles by enabling the Draw Tile Bounds checkbox.

    Enable Draw Tile Bounds to visualize the Navigation Tiles

  4. You can modify the way the Navigation Mesh is generated by going to the Generation section and changing its options.

Section Results

In this section you learned how to change the Display settings of your Navigation Mesh and how you can influence its generation by adjusting a variety of options.

4 - Creating your First Agent

In this section you will create a simple Agent that will roam around your Level by selecting a random location nearby and navigating to it. The Agent will wait a few seconds when it arrives at its destination before repeating the process again.

  1. In the Content Browser , right-click and select New Folder to create a new folder. Name the folder NavigationSystem .

  2. In the Content Browser , go to ThirdPersonBP > Blueprints and select the ThirdPersonCharacter Blueprint. Drag it to the NavigationSystem folder and select the option Copy Here .

    Drag the Third Person Character Blueprint into the Navigation System folder and select Copy Here

  3. Go to the NavigationSystem folder and rename the Blueprint to BP_NPC_NavMesh . Double-click the Blueprint to open it and go to the Event Graph . Select all input nodes and delete them.

  4. Right-click the Event Graph , then search for and select Add Custom Event . Name the event MoveNPC .

    Right click in the Event Graph and search for Add Custom Event

  5. Right-click the Event Graph , then search for and select Get Actor Location .

    Right click the Event Graph then search for and select Get Actor Location

  6. Drag from the GetActorLocation node and search for and select Get Random Reachable Point In Radius . Set the Radius to 1000 units.

    Drag from the Get Actor Location node and search for and select Get Random Reachable Point In Radius

  7. Drag from the Random Location pin of the GetRandomReachablePointInRadius node and select Promote to variable .

    Drag from the Random Location pin of the Get Random Reachable Point In Radius node and select Promote to variable

  8. Connect the MoveNPC node to the RandomLocation node you just created.

    Connect the Move NPC node to the Random Location node

  9. Right-click the Event Graph , then search for and select AI Move To . Connect the RandomLocation node to the AI Move To node.

    Right click the Event Graph, then search for and select AI Move To

  10. Right-click the Event Graph and search for and select Get a reference to self .

    Right click the Event Graph and search for and select Get a reference to self

  11. Connect the Self node to the Pawn pin of the AI Move To node. Connect the yellow pin of the Random Location node to the Destination pin of the AI Move To node, as seen below.

    Connect the Self node to the Pawn pin of the AI Move To node

  12. Drag from the On Success pin of the AI Move To node, then search for and select Delay . Set the Duration of the node to 4. Drag from the Completed pin of the Delay node, then search for and select MoveNPC , as seen below.

    Drag from the On Success pin of the AI Move To node and add a Delay node. Set Duration to 0.4. Drag from the Delay node and add a Move NPC node

  13. Repeat the steps above to add the nodes to the On Fail pin of the AI Move To node. Set the Duration of the Delay node to 0.1.

    Repeat the steps above to add nodes to the  On Fail pin of the AI Move To node

  14. Right-click the Event Graph , then search for and select Event Begin Play . Drag from the Event Begin Play node, then search for and select MoveNPC .

    Right-click the Event Graph, then search for and select Event Begin Play

    Drag from the Event Begin Play node, then search for and select Move NPC

  15. Compile and save the Blueprint.

  16. Drag your BP_NPC_NavMesh Blueprint to your Level and click Simulate . You should see your Agent roam around the Level.

    Your Agent is now moving in the Level

    Multiple Agents are moving in the Level

Section Results

In this section you learned how to create a simple Agent that roams around the Level using the Navigation Mesh .

Help shape the future of Unreal Engine documentation! Tell us how we're doing so we can serve you better.
Take our survey
Dismiss