Dynamic navigation

BeginnerLevel designerProgrammer

If you enable dynamic navigation, entities with navigation components don't need a navigation mesh asset. Instead, the entities generate navigation meshes dynamically.

Note

Make sure that the scenes you want the entities to navigate dynamically have navigation bounding boxes.

Enable dynamic navigation

You can enable and disable dynamic navigation in the global game settings asset.

  • On the entities you want to navigate dynamically, under the navigation component properties, next to Navigation mesh, make sure no navigation mesh is selected.

No navigation mesh selected

For more information about the navigation component, see Navigation components.

  • In the Solution Explorer (the bottom-left pane by default), select the Assets folder.

Select Assets folder asset

  • In the Asset View (the bottom pane by default), select the Game Settings asset.

Select Game Settings asset

  • In the Property Grid (the right-hand pane by default), under Navigation Settings, expand Dynamic navigation mesh.

Game settings

  • Select the Enable dynamic navigation checkbox.

Enable dynamic navigation checkbox

Dynamic navigation mesh properties

PropertyDescription
EnabledEnable dynamic navigation on navigation components that have no assigned navigation mesh
Included collision groupsThe collision groups dynamically-generated navigation meshes use. By default, meshes use all collision groups
Build settingsAdvanced settings for dynamically-generated navigation meshes

Enable and disable dynamic navigation from a script

Example code:

  1. // Find and enable the dynamic navigation mesh system
  2. dynamicNavigationMeshSystem = Game.GameSystems.OfType<DynamicNavigationMeshSystem>().FirstOrDefault();
  3. dynamicNavigationMeshSystem.Enabled = true;
  4. // This stops the dynamic navigation mesh system from automatically rebuilding in the folowing cases:
  5. // - loading/Unloading scenes
  6. // - adding/removing static collider components
  7. // - adding/removing navigation mesh bounding boxes
  8. dynamicNavigationMeshSystem.AutomaticRebuild = false;
  9. // ...
  10. if (/* any condition that should cause the navigation mesh to update (eg open/close door) */)
  11. {
  12. // Start an asynchronous rebuild of the navigation mesh
  13. var rebuildTask = dynamicNavigationMeshSystem.Rebuild();
  14. rebuildTask.ContinueWith((x) =>
  15. {
  16. if (x.Result.Success)
  17. {
  18. // The navigation mesh is successfully rebuilt
  19. }
  20. });
  21. }

See also