Modifying the Navigation Mesh Preparation Guide

This guide covers the preliminary steps needed to learn about modifying the Navigation Mesh.

Windows
MacOS
Linux

Overview

This document will guide you through the preliminary steps of creating a Level and AI Agent to demonstrate the different ways you can modify the Navigation Mesh.

Alternatively, you can download the full sample project, which includes all the material covered in this guide.

Objectives

  • Create a simple Level and add navigation by placing a Nav Mesh Bounds Volume Actor in the Level.

  • 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 menu, 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 build a basic Level with a Navigation Mesh.

2 - Creating Your Test Level

  1. Click File > New Level on the Menu Bar.

    Create a new Level

  2. Select the Default Level.

    Select the Default Level

  3. Select the Floor Static Mesh Actor in the World Outliner and from the Details panel, set the Scale to X = 10, Y = 10, Z = 1.

    Select the Floor Static Mesh Actor in the World Outliner

    Set the Scale to X = 10, Y = 10, Z = 1

  4. Inside the Content Browser, go to Geometry > Meshes and drag the TemplateFloor Static Mesh into the Level.

    Drag the Template Floor Static Mesh into the Level

  5. Go to the Place Actors panel and search for Nav Mesh Bounds Volume. Drag it into the Level and place it above the floor mesh.

    Drag the Nav Mesh Bounds Volume to the Level

  6. With the Nav Mesh Bounds Volume selected, go to the Details Panel and set the Scale to X = 20, Y = 20, Z = 5 to cover the entire floor area. Unreal Engine will automatically generate navigation inside the navigation bounds by default. A Navmesh Actor RecastNavMesh-Default should have also been added to the Level. Press the P key to visualize the Navigation Mesh in the Level.

    If no navigation is generated, go to Project Settings > Navigation System and enable the Auto Create Navigation Data checkbox.

    Set the Scale to X = 20, Y = 20, Z = 5

    The Navigation Mesh now covers the entire floor

  7. Go to the Place Actors panel and under the Basic category drag the Cube Static MeshActor into your Level.

    Drag the Cube Static Mesh Actor into your Level

  8. With the Cube selected, go to the Details Panel and set the Scale to X = 1, Y = 1, Z = 5.

    Set the Scale to X = 1, Y = 1, Z = 5

    The Cube is now rescaled

  9. Drag three more Cubes into the level and scale them as the one above. Place them around your floor to create four pillars as seen below.

    Drag three more Cubes into the level and scale them as the one above

  10. Next, add a stair and a platform in the middle. Inside the Content Browser, go to ThirdPerson > Meshes and drag the Linear_Stair_StaticMesh into the Level.

    Add a stair and a platform in the middle

  11. With the stairs selected, go to the Details Panel and set the Scale to X = 1.5, Y = 1, Z = 1.3.

    Set the Scale to X = 1.5, Y = 1, Z = 1.3

  12. With the stairs selected, drag the mesh while holding the Alt key to duplicate it.

    Duplicate the stairs mesh

  13. Go to the Place Actors panel and under the Basic category drag the Cube Static MeshActor into your Level. Go to the Details Panel and set the Scale to X = 14, Y = 4, Z = 0.1. Place the Actor on the edge of the stairs to create a platform, as seen below.

    Drag a Cube Static Mesh Actor into your Level and set the scale to X = 14, Y = 4, Z = 0.1

  14. Go to the Place Actors panel and under the Basic category drag the Sphere Static MeshActor into your Level.

    Drag a Sphere Static Mesh Actor into your Level

  15. With the sphere selected, go to the Details Panel and from the Collision section, set the Collision Presets to No Collision.

    Set the Collision Presets to No Collision

  16. Finally, duplicate the spheres and place them around your Level as shown below.

    Duplicate the spheres and place them around your Level

Section Results

In this section you created a simple Level and added a Nav Mesh Bounds Volume. You also added five spheres that will serve as target Actors for the Agent.

3 - Creating Your Agent

In this section you will create an AI Agent that will move between a list of target Actors.

  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 into the NavigationSystem folder and select the option Copy Here.

    Copy the Third Person Character Blueprint to the Navigation System folder

  3. Go to the NavigationSystem folder and rename the Blueprint to BP_NPC_ModNavMesh. Double-click the Blueprint to open it in the Blueprint Editor 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 the Event Graph, then search for and select Add Custom Event. Name it Move NPC

  5. Go to the My Blueprint panel and click the Add (+) button next to Variables to create a new variable. Name the variable TargetList.

    Create a new variable and name it Target List

  6. Go to the Details panel and click the dropdown next to Variable Type. Search for and select Actor > Object Reference.

    Set the variable type to Actor Object Reference

  7. Click the blue sphere icon next to Actor selection and click the Array option, as shown below. Click the Instance Editable checkbox to enable it.

    Click the blue sphere icon next to Actor selection and click the Array option

    Click the Instance Editable checkbox to enable it

  8. Drag the TargetList variable to the Event Graph and select the option Get TargetList.

  9. Drag from the TargetList node, then search for and select Last Index.

    Drag from the TargetList node, then search for and select Last Index

  10. Drag from the TargetList node and search for and select Get (a copy).

    Drag from the TargetList node and search for and select Get a copy

  11. Drag from the green pin of the Get node, then search for and select Random Integer in Range. Connect the green pin of the Last Index node to the Max pin of the Random Integer in Range node, as seen below.

    Drag from the green pin of the Get node, then search for and select Random Integer in Range

    Connect the green pin of the Last Index node to the Max pin of the Random Integer in Range node

  12. Drag from the Get node, then search for and select Promote to variable. Name the variable CurrentTarget and connect it to the MoveNPC node.

    Drag from the Get node, then search for and select Promote to variable

    Name the variable Current Target and connect it to the Move NPC node

  13. Drag from the CurrentTarget node, then search for and select Is Valid. Connect the IsValid macro node to the Set CurrentTarget node.

    Drag from the CurrentTarget node, then search for and select Is Valid

    Connect the IsValid macro node to the Set CurrentTarget node

  14. Drag the CurrentTarget variable to the Event Graph, then select Get Current Target. Drag from the CurrentTarget node, then search for and select Get Actor Location.

    Drag from the CurrentTarget node, then search for and select Get Actor Location

  15. Drag from the Return Value of the GetActorLocation node, then search for and select Get Random Reachable Point In Radius. Set the Radius value to 100.

    Drag from the Return Value of the GetActorLocation node, then search for and select Get Random Reachable Point In Radius

    Set the Radius value to 100

  16. Drag from the Random Location pin of the GetRandomReachablePointInRadius node and select Promote to variable. Name the variable RandomLocation. Connect the RandomLocation node to the IsValid node as shown below.

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

    Connect the RandomLocation node to the IsValid node

  17. Drag from the RandomLocation node, then search for and select AI MoveTo.

    Drag from the Random Location node, then search for and select AI MoveTo

  18. Drag from the Pawn pin of the AI MoveTo node, then search for and select Get a reference to self. Connect the yellow pin of the RandomLocation node to the Destination pin of the AI MoveTo node. Finally, set the Acceptance Radius of the AI MoveTo node to 50, as seen below.

    Drag from the Pawn pin of the AI MoveTo node, then search for and select Get a reference to self

    Connect the yellow pin of the Random Location node to the Destination pin of the AI MoveTo node

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

    Drag from the On Success pin of the AI Move To node, then search for and select Delay. Set the Duration to 4. Drag from the Delay node and add a Move NPC node

  20. 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 the nodes to the On Fail pin of the AI Move To node. Set the Duration of the Delay node to 0.1

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

  22. Compile and save the Blueprint.

  23. Drag your BP_NPC_ModNavMesh Blueprint into your Level and under the Details panel find the Target List and click the Add (+) button to add a new target Actor.

    Drag your BP_NPC_ModNavMesh Blueprint into your Level

    In the Details panel find the Target List and click the Add button to add a new target Actor

  24. Click the dropdown, then search for and select the Sphere Actor you created earlier.

    Click the dropdown, then search for and select the Sphere Actor

  25. Repeat the step above to add the remaining four Sphere Actors.

    Repeat the step above to add the remaining four Sphere Actors

  26. Click Simulate to see your Agent roam between goals in your Level.

    Click Simulate to see your Agent roam between goals in your Level

Section Results

In this section you created an Agent that roams between a list of target Actors. You can now move on to learning about Modifying the Navigation System.

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