Search Unity

Rebuild navmesh locks up Unity

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

  1. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    2,216
    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,216
    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,216
    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.