Search Unity

Optimize Navmesh using NavMeshBuilder.UpdateNavMeshDataAsync

Discussion in 'Navigation' started by Eck0, May 6, 2020.

  1. Eck0

    Eck0

    Joined:
    Jun 6, 2017
    Posts:
    48
    Hello everyone, I have performance problems with the navigation system.

    I have a terrain 160X160 lot which has several trees all over the map and on this map agents are created on one side of the map and on the other opposite side of the map and these agents walk to the other opposite side.

    I am using NavMeshBuilder.UpdateNavMeshDataAsync continuously in a coroutine to update the new existing areas since each tree generates an area around it 1x1 and each agent when parking generates an area of 0.25X0.25.

    I have observed that using NavMeshBuilder.UpdateNavMeshDataAsync forces to recalculate the route in all agents which increases the cost ...

    He could also observe that calculating a route from one place to another takes a little time, which increases the cost even more if it is continuously recalculated with the above mentioned

    Is there a more efficient way to recalculate the navmesh?
    for example having a source browser assigned and when recalculating the navmesh assign it the source navmesh and only update the areas that have been changed

    Is there a way to optimize routes, i.e. if I have a route from one side of the map to the other side of the map, can I calculate only a small part of that route? for example 25% of the total route?

    I need urgent help on this subject as it is the basis of my entire project.
     
  2. Eck0

    Eck0

    Joined:
    Jun 6, 2017
    Posts:
    48
    I would like to know if there is any possibility to assign an area to a navmeshobstacle to avoid doing NavMeshBuilder.UpdateNavMeshDataAsync.
     
  3. Eck0

    Eck0

    Joined:
    Jun 6, 2017
    Posts:
    48
    Is this forum good for anything? the 2 times that i commented did not receive any response.
    The members of the unit do not enter the forum?
    Is it so difficult to answer if a navigation obstacle can generate an area over the navigation cut?
    I'm a little outraged at this forum...
     
  4. apollyonbob

    apollyonbob

    Joined:
    Jan 16, 2012
    Posts:
    10
  5. Eck0

    Eck0

    Joined:
    Jun 6, 2017
    Posts:
    48
    What part of the post do you not understand?
    I am asking if it is possible to assign an area over a cut area (example, when activating a navigation obstacle, assign an area over the cut area).

    at the moment I use UpdateNavMeshDataAsync but this updates the entire mesh which makes a huge cost.

    So I ask again if I can update the mesh in a more efficient way...
     
  6. apollyonbob

    apollyonbob

    Joined:
    Jan 16, 2012
    Posts:
    10
    Listen, buddy, you know what, alright, you get to hear some brutal truth: What part of your post do I not understand? All of it. I don't understand what you're saying, because "assign an area over the cut area" isn't English man and I'm afraid that's all I speak. So I tried to help, and sent you to someplace where it talks about Obstacles and NavMeshes, because you shouldn't BE using UpdateNavMeshDataAsync to account for Obstacles. If you place a NavMeshObstacle down, like that tutorial shows, it will automatically update. Which'd you know, if you'd gone through that tutorial.

    I tried to be nice. I sent you to the places where if you go AND LEARN on your OWN, you will probably find the answer you seek. But this is the final message you will receive from me, because going aggro on people trying to help you is about the easiest way to never get help from anyone anywhere, ever. Little life lesson for ya there.
     
    x1alphaz1 likes this.
  7. DwinTeimlon

    DwinTeimlon

    Joined:
    Feb 25, 2016
    Posts:
    300
    You can improve the performance in several ways.

    1. Divide your navmesh in different areas and use NavMeshLinks to connect them
    2. Rewrite NavmeshSurface and NavMeshModifier to fit your needs (especially how you collect sources)
    3. Only Update your NavMeshSurface when something changes, e.g. Trees should only processed once, if they do not change
    4. Work with NavMeshObstacle for objects which change often
    5. Try to play around with voxel size, bigger values are faster, as the NavMesh is not as detailed
    6. Play around with this number NavMesh.pathfindingIterationsPerFrame
    7. If this all does not work, maybe the current NavMesh system is not good enough for your project -> try checkout A* Pathfinding Plugin in the Asset Store.
     
  8. Eck0

    Eck0

    Joined:
    Jun 6, 2017
    Posts:
    48
    Thank you very much for the recommendations.
    i opted to divide the map into a list of navigation surfaces of a size of 1 for each navigation surface, the problem is that I don't know how to join each other without having to navigate navmeshlink since there are no jumps.
     
  9. creativelefty

    creativelefty

    Joined:
    Jan 28, 2017
    Posts:
    10
    Hope someone can give me some advice. Currently, I have a navMeshSurface (call it mySurface) with NavMeshCollectRootSources2D + NavMeshCacheSources2D components added. (It has approx. 1000 sources.)
    I use mySurface.UpdateNavMesh(mySurface.navMeshData) and the navMesh updates correctly but its very slow (about +70ms).
    So I'd like to use UpdateNavMeshDataAsync, but not quite sure how to input the 'sources' part.
    Code (CSharp):
    1. NavMeshBuilder.UpdateNavMeshDataAsync(mySurface.navMeshData, mySurface.GetBuildSettings(), ???, mySurface.navMeshData.sourceBounds
    I created a reference to mySurface's NavMeshCacheSources2D component (calling it navCache) and then tried to use it as such:
    Code (CSharp):
    1. NavMeshBuilder.UpdateNavMeshDataAsync(mySurface.navMeshData, mySurface.GetBuildSettings(), mySurface.navCache.Cache, mySurface.navMeshData.sourceBounds
    but doesn't seem to update the mySurface navMesh. Can anyone please let me know what is the proper way to grab the cached sources and then use them in UpdateNavMeshDataAsync. Appreciate it.
     
    jacksonkr likes this.
  10. jacksonkr

    jacksonkr

    Joined:
    Jan 22, 2013
    Posts:
    23
    I found out about `UnityEngine.AI.NavMeshSurface.CollectSources` but it must be private / protected since I'm not able to use it. Is there any new information about how to get references to the current cache used for a NavMesh Surface ?

    source

    ** EDIT **

    CollectSources is a static method eg `NavMeshBuilder.CollectSources`

    source
     
    Last edited: Oct 28, 2022