Bake navmesh during runtime?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By KijeviGombooc

I want have navigation for my prcedurally generated terrain, is it possible somehow?

Related: Check out Expose navmesh bake function to scripting · Issue #22767 · godotengine/godot · GitHub and GitHub - TheSHEEEP/godotdetour: A GDNative implementation of the detour/detourcrowd library for Godot. .

Not possible currently, but Navmesh during runtime has been merged into the 4.0 build. In the meantime you can create NavMeshes from CSGBoxes as per Expose navmesh bake function to scripting · Issue #22767 · godotengine/godot · GitHub

SgtLion | 2020-09-15 12:44

:bust_in_silhouette: Reply From: Zylann

It doesnt seem to be possible. I see the Bake Navmesh button in the editor calls this in the editor code:

EditorNavigationMeshGenerator::get_singleton()->bake(node->get_navigation_mesh(), node)

Which by the name means it’s not available in exported game, and probably not even exposed to editor scripting. It uses the Recast library internally.

If you need that for your game, you have two options:
Either you generate your navmesh from geometry that you generated yourself already, and use NavigationMesh functions to construct it: NavigationMesh — Godot Engine (3.1) documentation in English
(don’t just take your meshes directly though, it’s a navmesh so it needs to be offset).

If you need the editor baker, you could do a feature request on Github, or expose it yourself by modifying the engine (it’s open source after all).

I created a simple unit that moves to mouse click on a navmesh. It works properly when the navmesh is baked in editor, but when I use the method NavigationMesh.create_from_mesh(Mesh mesh) the path I get from
Navigation.get_simple_path(Vector3 start, Vector3 end) is a 0 sized array, so it doesn’t seem to work. Any idea why? Also, is there a way to see the navmesh in the running game for debugging purposes?

KijeviGombooc | 2019-07-19 16:38

I just checked the other methods of NavigationMesh (none of them have description, I might add them if im sure about them and if i learn how to add descriptions :smiley: ). So by checking them I checked and my mesh was added as navmesh, but I don’t knwo why it’s not working.

KijeviGombooc | 2019-07-19 16:58

Ok, got it working, just had to tick “enabled” to false then back to true, so far doing it in editor after starting. But there is a problem, the pathfinding seems to only work this way with only one triangle of the mesh(which is a not subdivided plane right now for me). When I click to other tri, the unit is going to some place in first tri.

KijeviGombooc | 2019-07-19 17:15

Ok the stopping of movement bug was because the script on the Unit was too simple yet, had to make it better, won’t go into details, it was simple fix :smiley:
So, the navigation was created in runtime! Now I just gotta figure out a way to offset the mesh, do you have any idea?
Also I’m gonna have to see how to create navmesh from more than one mesh. Do you know if there is a way to maybe combine meshes so I can still use a single mesh for this?

KijeviGombooc | 2019-07-19 17:34

:bust_in_silhouette: Reply From: zen3001

since this doesn’t seem to be a possibility natively, you could get the navigation lite addon, you can get it directly from the engine, or here: GitHub - MilosLukic/Godot-Navigation-Lite: Godot plug&play implementation of detour. It allows user to have multiple navigation meshes, fast cached obstacles, and realtime navmesh changes.