Setting up a NavMesh in Unreal Engine 5

Demo video showing the NavMesh AI in the Unreal Engine 5 Editor

Many modern games have AI controlled characters to add to the atmosphere of a scene or to provide gameplay to the player.

To achieve this in Unreal Engine 5 we need to have a generate a mesh for the characters to navigate through and also create a character that has AI navigation correctly setup. These are easy steps but issues can occur if not setup correctly!

In this guide we are showing you how to set up a NavMesh and basic AI Character in Unreal Engine 5.

Setting up the NavMesh

Firstly, click Window, then Place Actors. This will show the Place Actors window in the editor. This window allows you to spawn basic objects and volumes into your Unreal Engine 5 level.

Opening the place actors editor window.

Then, add a NavMeshBoundsVolume actor to your level. This can be found in the Modes panel under the “Volumes” category.

Adding the nav mesh bounds volume to the level.

Scale and position the NavMeshBoundsVolume to fit around the area that you want the AI to be able to navigate.

This can be as large or as small as you require. Bigger nav meshes take longer to generate unless you use dynamic generation. Click here to read about dynamic nav mesh generation.

Scaling and positioning the nav mesh bounds volume around the level geometry.

Now to confirm your Nav Mesh is setup correctly for your level, Press the “P” key on your keyboard to see the mesh visualized in the level.

Enabling the debug navigation view to ensure the nav mesh is set up correctly.

Moving the AI Character

For this guide we are using the third person template that Unreal Engine 5 provides.

This means we can have an animated character to test the AI Navigation.

To enable our third person character blueprint to navigate the level, first drag your character into the level.
This can be found in the “Third Person / Blueprints” folder in the Content Drawer if you created your project using the Third Person Template.

Adding the AI character to the level.

In the blueprint editor of the character, create a “Begin Play” event and connect the “AI MoveTo” node as shown in the image below.

Adding the AI MoveTo node to the blueprint graph.

Next, create a “GetRandomReachablePointInRadius” node and connect the output yellow vector pin to the yellow “Destination” pin on the “AI MoveTo” Node.

Connecting the GetRandomReachablePointInRadius node to the Ai MoveTo node.

Then create and connect a “Get Actor Location” node to the “Origin” yellow vector pin. This Origin position is where the random movement is calculated around.

Connecting the Get Actor Location ndoe to the GetRandomReachablePointInRadius node. This gives us the origin for navigation checks.

Set the green “Radius” pin value to the distance you want your AI to roam around. In this guide we are using “2000”.

Setting the navigation radius to 2000.

Create a “Reference to Self” node and connect this to the blue “Pawn” pin of the “AI MoveTo” node.

Setting the AI Pawn to the self character reference.

Finally, create a “Delay” node then connect it to the “On Success” pin. Connect the end of the Delay back into the AI MoveTo node. This will continuously navigate the AI character around the Navigation Mesh.

Adding and connecting the Delay node to the On Success pin and the AI MoveTo Node.

Now you can click “Play” and the character will then begin moving towards random locations in your level using the NavMesh.

Demo Video

Example video showing the AI moving around the level using the NavMesh in the Unreal Engine 5 editor.

Download the Project Files

Conclusion

Now your character is moving around the level all by itself! This AI behaviour is very basic but can be expanded upon greatly using many of the great AI features in Unreal Engine 5. To learn more about AI and Navigation in Unreal Engine consider reading further using the links below.

Further Reading:
How to smoothly rotate AI characters in Unreal Engine
Open world navigation in Unreal Engine
Dynamically generated navigation in Unreal Engine
Official Unreal Engine Navigation documentation

Be the first to comment

Leave a Reply

Your email address will not be published.


*