Basic Navigation

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

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.

    Create-Project.png

  2. Select the Third Person template and click Next.

    Create-Project2.png

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

    Basic-Create-Settings.png

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.

    Basic-Drag-NavmeshBounds.png

  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.

    Basic-NavMesh-Scale.png

    Basic-NavMesh-Scale2.png

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

    Basic-RemoveChar.png

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

    Basic-NavMesh-Visualize.png

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

    Basic-NavMesh-Offset.png

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.

    Basic-NavMesh-SelectRecastActor.png

  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.

    Basic-NavMesh-Recast-Triangles.png

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

    Basic-NavMesh-Visualize2.png

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

    Basic-NPC-Copy.png

  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.

    Basic-NPC-AddCustomEvent.png

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

    Basic-NPC-GetLocation.png

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

    Basic-NPC-RandomPoint.png

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

    Basic-NPC-CreateTargetLoc.png

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

    Basic-NPC-CreateTargetLoc2.png

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

    Basic-NPC-AIMoveTo.png

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

    Basic-NPC-Self.png

  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.

    Basic-NPC-AIMove-Connected.png

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

    Basic-NPC-Success.png

  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.

    Basic-NPC-OnFail.png

  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.

    Basic-NPC-BeginPlay1.png

    Basic-NPC-BeginPlay2.png

  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.

    Basic-NPC-Final1.gif

    Basic-NPC-Final2.gif

Section Results

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

언리얼 엔진 문서의 미래를 함께 만들어주세요! 더 나은 서비스를 제공할 수 있도록 문서 사용에 대한 피드백을 주세요.
설문조사에 참여해 주세요
건너뛰기