Search Unity

Access NavMeshSurface vertices

Discussion in 'Navigation' started by beatdesign, May 15, 2019.

  1. beatdesign

    beatdesign

    Joined:
    Apr 3, 2015
    Posts:
    137
    Hi to all, this could seem a bit odd, but.. is there a way to access NavMeshSurface vertices?
    I know that If I have a Navmesh, I can do:

    verts as (Vector3)
    ids as (int)
    NavMesh.Triangulate(verts, ids)
    mesh = Mesh()
    mesh.vertices = verts
    mesh.triangles = ids
    meshFilter.mesh = mesh

    ..but what if I have a Navmeshsurface instead?
     
  2. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    As far as I know the NavMeshSurface is only used to mark areas for the NavMeshBuilder to be used in creating the navmesh. It doesn't contain any actual navmesh data, so there's nothing to access.
     
  3. beatdesign

    beatdesign

    Joined:
    Apr 3, 2015
    Posts:
    137
    Not true: I build the navmesh at runtime using NavmeshSurface:
    Code (CSharp):
    1. for (int i = 0; i < surfaces.Length; i++)
    2.         {
    3.             surfaces [i].BuildNavMesh ();  
    4.         }  
    How can I access the vertices of the built navmesh?
     
  4. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    You can get the verts of all NavMeshes by using NavMesh.CalculateTriangulation() and access the vertices array in the returned NavMeshTriangulation. Keep in mind this will be ALL NavMesh data, not limited to a NavMeshSurface, and the NavmeshSurface doesn't seem to have anything to return its triangulation based on only its own data to you.
    It's also apparently impossible to calculate triangulation using a given set of data, there's no argumented version of that function anywhere.