Creating a movable Navmesh in Unity

One major problem with Unity Navmesh is they are considered to be static. If you change the transform of the Navmesh object the Navmesh doesn’t move along with the object. So how do we create a Navmesh that moves along with the object?

Static Navmesh
Dynamic Navmesh

The navigation package built with Unity does not allow you to create a Navmesh on a non-static object as we saw in our Enemy AI tutorial. You need to add an experimental package called Navmesh Building Component to achieve this.

Adding Navmesh Building component to your project

  1. Go to Windows>Package Manager.
  2. Select Unity registry in the packages drop down.
  3. Click on the + sign and select add package by Name.
  4. In the name text field paste this URL “com.unity.ai.navigation”
  5. Click on Add.
  6. This will install Unity Navmesh Building component to your project.
  7. You will get a warning that Unity does not support experimental packages. You can ignore it as of now.

Adding a Dynamic Navmesh

Normally there is no need to add any component to your Navmesh plane. You can just select the plane, set it as a Navigation static and bake your Navmesh.

To use the Navmesh Building component you need to attach a Navmesh surface component to your plane. You can get your plane as a non-static object in this case.

Unity Black Friday Deals

Go to the Navigation tab and set your Agent parameters. Do not bake the mesh from the navigation window.

Go to the inspector property of your plane and find the Navmesh surface component you attached earlier.

Click on bake on the Navmesh surface component.

Now you have baked a dynamic Navmesh.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.