Search Unity

Question How to convert NavMeshData generated by the new NavMeshSurface component to a mesh asset?

Discussion in 'Navigation' started by Xtro, Apr 17, 2023.

  1. Xtro

    Xtro

    Joined:
    Apr 17, 2013
    Posts:
    610
    In the old system, it was possible to retrieve the vertices and indices of a navmesh via NavMesh.CalculateTriangulation method.

    Now how can I do this with the new system. I have a reference to a NavMeshSurface and I build the nav mesh data via NavMeshSurface.BuildNavMesh method but I can't find anything similar to CalculateTriangulation method in NavMeshSurface object or NavMeshSurface.navMeshData object.

    Please don't tell me this is not possible in the new system :(
     
  2. Xtro

    Xtro

    Joined:
    Apr 17, 2013
    Posts:
    610
    I found a workaround-like solution: Temporarily adding the nav mesh data to the main (old) NavMEsh class.

    Code (CSharp):
    1.                 var NavMeshDataInstance = NavMesh.AddNavMeshData(NavMeshSurface.navMeshData);
    2.                 var Triangulation = NavMesh.CalculateTriangulation();
    3.                 NavMesh.RemoveNavMeshData(NavMeshDataInstance);
    4.