Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Rebuild navmesh locks up Unity

Discussion in 'Navigation' started by snacktime, Jun 13, 2019.

  1. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    2,396
    I have a feeling why so hoping someone from Unity might be able to confirm. Unity goes to 0% cpu utilization and becomes unresponsive. This is while rebuilding at runtime after the build sources change.

    The following code is where it happens. GetBuildSources returns as I have a debug log at the end of that method which runs. That's the last line in the editor log except for a bunch of warnings of job temp allocations being more then 4 frames old that goes on for a bit, probably just coincidental. AddNavmeshData does a remove and add of the navmesh instance data.

    Where I think the problem likely lies given it takes 1-20 tries to trigger, is that I'm doing a bunch of job based navmesh queries. As far as I know I'm adding NavMeshWorld.AddDependency to everything. But if this lockup would be expected in the case I'm missing one that would be helpful to know. The other question is should I be refreshing the NavMeshWorld instance I'm using after resetting the navmesh instance data? Currently I only call NavMeshWorld.GetDefaultWorld() once and reuse it for the life of the game.

    Code (csharp):
    1.  
    2. AsyncOperation op = NavMeshBuilder.UpdateNavMeshDataAsync(NavMeshData, GetSettings(), GetBuildSources(), GetBounds());
    3. yield return op;
    4.  
    5.  AddNavMeshData();
    6.  
     
  2. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    2,396
    I'm also curious about NavMeshWorld.AddDependency. That makes the navmesh system wait on the given job dependencies. The only reason for this api would be queries shouldn't be happening while rebuilding right? If that's the case there is no protection against the rebuild starts and then more jobs doing queries are scheduled, which will likely result in queries done against a navmesh that's being updated and then a potential crash.
     
  3. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    2,396
    Ok so queries while a build is running does in fact appear to be the issue. Easy enough to fix but this really should be in the docs given it's entirely on the end user to prevent a hard crash, ie you have no built in mechanism for handling this.
     
  4. kingstone426

    kingstone426

    Joined:
    Jun 21, 2013
    Posts:
    7
    Hey snacktime! Did you solve the problem?

    I am also getting random crashes when calling UpdateNavMeshDataAsync and can't find a solution.
    The problem disappears if I call UpdateNavMeshData instead (but then I get framerate spikes).

    I have no NavMeshAgents in the scene and I am not executing any navmesh queries.
    I am not using the jobs system for any custom threaded operations.
    I don't use NavMeshWorld, or anything else from the UnityEngine.Experimental.AI namespace.
    I don't use the NavMeshComponents from github, just what's in Unity 2019.2.0f1 by default.

    The log is flooded with job temp allocation warnings and, weirdly, it seems they continue flooding even after the UpdateNavMeshDataAsync async operation has completed.

    Any and all help appreciated!