Overview
Unreal Engine’s Navigation System allows Agents to navigate the Level using a Navigation Mesh for pathfinding. In addition to the various Runtime Generation methods for the Navigation Mesh, the system also includes a way to only build the navigation locally around specific targets.
Navigation Invokers are Blueprint Actor components that generate the Navigation Mesh around the Agent at runtime. Using Navigation Invokers removes the need to build the Navigation Mesh in the editor and can also limit the number of tiles generated at runtime.
Navigation Invokers are ideal for big Levels where building the Navigation Mesh in the editor is impractical.
Goals
In this guide you will learn to use Navigation Invokers with your Agents to generate the Navigation Mesh during gameplay.
Objectives
-
Create a new Level and configure the Navigation System to use Navigation Invokers.
-
Modify the ThirdPersonCharacter Blueprint to roam around the Level using Navigation Invokers.
1 - Required Setup
-
In the New Project Categories section of the menu, select Games and click Next.
-
Select the Third Person template and click Next.
-
Select the Blueprint and No Starter Content options, then click Create Project.
Section Results
You created a new Third Person project and are now ready to learn about Navigation Invokers.
2 - Creating Your Test Level
-
Click File > New Level from the Menu Bar.
-
Select the Default Level.
-
Select the Floor Static Mesh Actor in the World Outliner and go to the Details panel. Set the Scale to X = 100, Y = 100, Z = 1.
-
Click Settings > Project Settings and go to the Navigation System category. Enable the Generate Navigation Only Around Navigation Invokers checkbox.
-
Go to the Navigation Mesh category and scroll down to the Runtime section. Click the Runtime Generation dropdown and select Dynamic.
-
Go to the Place Actors panel and search for Nav Mesh Bounds Volume. Drag it into the Level and place it on the floor mesh. Scale the Nav Mesh Bounds Volume to X = 500, Y=500, Z = 10.
Section Results
In this section you created a new Level and configured the Navigation System to use Navigation Invokers.
3 - Creating your Agent
-
In the Content Browser, right-click and select New Folder to create a new folder. Name the folder NavigationSystem.
-
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.
-
Navigate to the NavigationSystem folder and rename the Blueprint to BP_NPC_Invoker. Double-click the Blueprint to open it and go to the Event Graph. Select all input nodes and delete them.
-
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 Get Actor Location.
-
Drag from the GetActorLocation node and search for and select Get Random Reachable Point In Radius. Set the Radius to 1000.
-
Drag from the Random Location pin of the GetRandomReachablePointInRadius node and select Promote to variable.
-
Connect the MoveNPC node to the RandomLocation node you just created.
-
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 Get a reference to self.
-
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.
-
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.
-
Repeat the steps above to add these nodes to the On Fail pin of the AI Move To node. Set the Duration of the Delay node to 0.1.
-
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.
-
Go to the Components tab, click the Add Component dropdown, then search for and select Navigation Invoker.
-
With the Navigation Invoker component selected, go to the Details panel and find the Navigation section. Here you can change the Tile Generation Radius (radius around the actor used to generate Navigation Mesh tiles) and Tile Removal Radius (radius from the actor used to to remove Navigation Mesh tiles). For this example, set these values to 3000 and 5000, respectively.
-
Compile and save the Blueprint.
-
Drag several BP_NPC_Invoker Blueprints to your Level and click Simulate to see the navigation generating around each Agent.
If you don’t see the navigation, press P on your keyboard to visualize the Navigation Mesh.
Section Results
In this section you created an Agent that roams around the Level and uses the Navigation Invoker component to build the Navigation Mesh around itself.