Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

LocalNavMeshBuilder UpdateNavMesh async

Discussion in 'Navigation' started by Ardinius, Aug 5, 2018.

  1. Ardinius

    Ardinius

    Joined:
    Oct 4, 2015
    Posts:
    57
    Hi,
    Having a very large localNavMeshBuilder with a low agent size is of course very hard for performance, as the voxel size of the localNavMeshBuilder is very small.

    Looking a the function UpdateNavMesh
    https://github.com/Unity-Technologi...ssets/Examples/Scripts/LocalNavMeshBuilder.cs

    Code (CSharp):
    1.     void UpdateNavMesh(bool asyncUpdate = false)
    2.     {
    3.         NavMeshSourceTag.Collect(ref m_Sources);
    4.         var defaultBuildSettings = NavMesh.GetSettingsByID(0);
    5.         var bounds = QuantizedBounds();
    6.  
    7.         if (asyncUpdate)
    8.             m_Operation = NavMeshBuilder.UpdateNavMeshDataAsync(m_NavMesh, defaultBuildSettings, m_Sources, bounds);
    9.         else
    10.             NavMeshBuilder.UpdateNavMeshData(m_NavMesh, defaultBuildSettings, m_Sources, bounds);
    11. }
    Can anyone explain asyncUpdate and what is is doing? Is this a new 4.6 feature that allows coroutines to run code that runs on all threads?
    Essenancally is this asking the navMesh to be rebuilt as fast as possible over and over? (As it apears to max all my cores).

    I put the code inside of UpdateNavMesh in a simple timer code of:
    float delayTimer -=Time.deltaTime;
    if(delayTime <0)
    {

    }

    This is just a hack of course but greatly improve performance, i am looking for more understanding of async and how to control it with better code.

    Ideally i wish to control when i update the navMesh, could i just remove the UpdateNavMesh from the Start() while loop and call it manually?
     
    Last edited: Aug 13, 2018
  2. Ardinius

    Ardinius

    Joined:
    Oct 4, 2015
    Posts:
    57
    Hi,
    my understanding is now that
    Code (CSharp):
    1. IEnumerator Start()
    2.     {
    3.         while (true)
    4.         {
    5.             UpdateNavMesh(true);
    6.             yield return m_Operation;
    7.         }
    8. }
    The yield is rerunning the UpdateNavMesh as soon as it has finished, FYI if anyone needs to control this also for perfomance reasons.