Creating NavGraphs

You can augment the NavMesh that you create for your terrains by adding custom NavGraphs. Often, the placement of these NavGraphs is implicit in the design of the game level. In this case, the NavGraphs can be created during the NavData generation process, typically in a post-processing phase that you carry out after generating the NavMesh for the level. However, you can also create and spawn the NavGraph dynamically at runtime. For example, you might need to use this approach if you want the NPCs in your game to be able to use ladders that can be moved to arbitrary places.

Building the NavGraph

You can craft a NavGraph using a NavGraphBlobBuilder object, as follows:

  1. Create a new instance of the NavGraphBlobBuilder class, and use its methods to add vertices and edges.
  2. Create a new NavData object to hold your NavGraph.
  3. Add your new NavGraph to the NavData by calling the NavData::AddNavGraph() method, passing your NavGraphBlobBuilder as a parameter.

Note that you can add multiple NavGraphs to the same NavData object. However, you cannot add NavGraphs to a NavData object that already contains a NavMesh, or to a NavData object that has already been added to a Database.

Creating during data generation

If you are creating your NavGraph as part of your data generation process, you should package up your new NavData object the same way you do for the NavData objects created automatically by the data generation system.

Creating at runtime

If you are creating your NavGraph dynamically at runtime, you can simply add your NavData object to the Database the same way you do for the NavData objects that contain your pre-generated data.

Call either NavData::AddToDatabaseImmediate() or NavData::AddToDatabaseAsync().

Example

For a code example that shows how to create a NavGraph during a post-processing phase of the data generation process, see the Tutorial_Generation_postProcess.cpp file.

For a code example that shows how to create and add a NavGraph on the fly, see the Tutorial_NavTag.cpp file.