HOW-TO: Generate Navigation Data (Navmesh)

62f5ec7d-97ac-42c4-90b6-692880b3e37d.jpg

In order for the NPCs in the game to move and behave properly, you need to generate Navigation Data for them.

This is one of the steps you should always keep in mind while preparing your mods. Below you can learn exactly why it is needed step (with a test scenario) and what must be done to fix the problem.


Why is Navmesh/Navigation data important:

  • it is needed for all NPCs to behave properly (even Geralt in some cases)

  • it is what the NPCs use to walk on and pathfinding

  • without it if (for example) a NPC gets knocked down, they will die immediately


1. What happens if you don’t generate the navmesh

Let’s start with a quick test.

First, add a an object such as a table (mesh) in the World you are currently working on in REDkit.

Activate a layer (double click on it in Panel > Scene), then open the Asset Browser (CTRL+A) and search for baron_table.w2mesh in the environment\decorations\furniture\barons_manor\ folder.

If you see a prompt asking you what kind of mesh you want it to be, choose Static Mesh.

24659556-d4b0-411e-aaba-962b9760b47c.png

Mesh types:

  • Mesh - will place a mesh with no collision.

  • Static Mesh - will place a mesh with collision (if the mesh has collision setup).

  • Rigid Body Mesh - will place a mesh with collision and physics enabled (if the mesh supports it).

Now start your level in the game from the Editor.

Once you are on the level in the game, open the console command with the ~ key. Type in spawn('1hand') to spawn an enemy NPC.

You should notice that:

  • Geralt cannot walk through the table

  • but the NPC has no trouble walking through it.

That is because there is no navmesh telling him to avoid it!

Check the section below to solve that problem.


2. How to generate navmesh for simple areas

How to fix that problem? All it takes in one click and a bit of patience.

Go to Publish menu and press Generate Navigation Data. The process can take up to several minutes - depending on the complexity of your level. But you can leave that step till the very end, before actually testing your level in the game.

Please remember: you need to use Generate Navigation Data again after: you add/move/remove static meshes, larger foliage or edit the terrain.

Let’s see if that helped with our table test described above.

Start your level in the game from the Editor again, and open the in-game console command (~ key).

Type in spawn('1hand') to spawn an enemy NPC. Notice anything different?

The NPC should now also avoid the table!


3. Complex structures need Navigation Instances

For more complex environments we will need to use Navigation Instances.

First, we will have to build some more challenging obstacles for our NPC. Let’s add a more complex mesh into the World. Open the Asset Browser and find:

  • environment\architecture\human\redania\nomans_land\baron_castle\baron_stables_platforms_interior.w2mesh

Move it a bit lower towards the ground so we can safely jump up and down it, but still high enough so that you can also walk under it.

Go to the properties tab of the mesh you just added. In the CStaticMeshComponent section change the pathLibCollisionType setting to PLC_StaticWalkable.

This means the game will treat this as a surface on which NPCs will be able to walk on after navigation generation.

 

 

 

 

 

You’re going to need some stairs to reach the platform.

Let’s also add another mesh:

  • environment\architecture\human\redania\novigrad\novigrad_harbour_shore_set\nvg_harbour_wood_stairs_long.w2mesh

…and just like we did a moment ago, change the pathLibCollisionType setting to PLC_StaticWalkable.

 

Without a navmesh instance, these settings will not change anything.

If you were to test the level right now (as described above) and spawn an NPC, you will notice that:

if you run up and down the walkway, the NPC doesn’t really know how to follow you

whether from the ground to the top, or from the top to the ground depending on where you spawn him.

while you are both on the walkway, knocking the NPC over with Aard (fully knocked over, not just knocked back) will result in them dying as they try to get up.

Why is that? Because the NPC can’t find valid navmesh.

Let’s fix that!

Adding navigation instances

  1. Go to the Scene Panel. Create a new layer group (right click on the world icon with your level’s name and select Add group). Find your group and add a layer within it that has the Navigation Build tag and auto-static type.

 

 

 

  1. Activate your new layer (double-click the layer, see its name in bold).

  2. Now right-click in the Viewport (level preview) to add Navigation > Add Navmesh Instance

 

  1. A red Navmesh Instance area should appear in the World.

  1. Move the area down so it covers the bottom of the mesh and scale the area so it generously covers the whole mesh and area you will want to generate a navmesh for. Make sure it is at least 5 meters higher than the highest point of any mesh inside of the red area. Always better to make the area too big instead of too small.

     

  2. Select the navmesh layer and go to its properties. Find the CNavmeshComponent > SNavmeshParams and change the useTerraingInGeneration parameter to True.

  3. While the navmesh area is still selected, right-click inside of the area where you expect navmesh to be generated and a place which is accessible. Choose Navmesh: Move generation root here - this is the point where the generation of the navmesh starts.
    The root’s placing, as you will see by the end of this tutorial, is important. If your area is more complex, you may need to add multiple Generation Roots (from the same menu).

  4. In the Scene Panel, right-click the navmesh instance within your previously created navmesh layer and choose Generate Navmesh.

  5. You should see a pop-up saying the navmesh instance has been generated successfully.

     

  6. Save your work and the layers added to your level.

  7. If you enable the NavMesh debug filter you can see the results of what we have been setting up. Please note: the NavMesh filter only shows navmesh instances, and not the whole navmesh on the level.

     

  8. To make sure that everything will work correctly, check the outside borders of the debug navmesh. If you see a green border, that means that NPCs will be able to walk from one side of it to another. If the border is black, then they will only be able to walk from the outside in, but not from the inside out.

    In the screenshot the borders are green all around the areas edge - which is the result we were looking for. Additionally, the borders near the walkway are black - which is also as we hoped as we don’t want NPCs to be able to cross these areas.
    If your outside borders are not green, you will need to go back to the step where we moved the Generation Root.

     

  9. Now we need to Generate Navigation Data (Publish menu).

     Once that is done you may need to restart the Editor to fix the issue of disappearing textures.

  10. Time for testing:

    • load the level and all the layers

    • load the game

    • spawn an NPC with spawn('1hand') in the console command (~).

    • make them chase you up and down the stairs

    • check if the NPC can cross the borders of the navmesh area

  11. If everything worked fine, the NPC should now properly follow you and as you knock them from the top of the walkway with Aard, they should properly get up - instead of dying like before.

 

 

______________________________________
The Witcher 3: Wild Hunt Complete Edition © 2024 CD PROJEKT S.A. Published by CD PROJEKT S.A. Developed by CD PROJEKT RED. CD PROJEKT®, The Witcher®, REDengine® are registered trademarks of CD PROJEKT Capital Group. All rights reserved. The Witcher game is set in the universe created by Andrzej Sapkowski in his series of books. All rights reserved.