How to generate a Navmesh in Code

I have absolutely no problem pragmatically generating a complex mesh for a mesh filter to dynamically generate my level. (By generating the arrays of verts and tris etc.) Now I want to dynamically generate a NavMesh in the same way for very precise control over the traversable area.

I have been searching for a while to find the scripts to do this and have stumbled across many references to the fact that its possible (without any code snippets). But I’m mostly just wading through page after page of how to use the unity editor to bake the NavMesh. At this point I’m getting a bit frustrated with search engines…

I probably just need to be linked to the right page.
How do you generate a NavMesh in code? (preferably c#)

thanks in advance

Probably the best you can do is copy how NavMeshSurface.BuildNavMesh but change how CollectSources() is implemented to limit it to your desired geometry.

However, I don’t think this lets you specify the geometry of the navmesh – just the geometry used to generate the navmesh. This would give you more control over the resulting navmesh, but not absolute control.

I believe you’d have to write your own navigation system to get it to use your custom navmesh. You could integrate recast or one of its C# reimplementations.