Search Unity

NavMeshBuilder.BuildNavMeshAsync() where is it ?

Discussion in 'Navigation' started by PixelizedPlayer, Sep 20, 2018.

  1. PixelizedPlayer

    PixelizedPlayer

    Joined:
    Feb 27, 2013
    Posts:
    410
    According to the documentation:

    https://docs.unity3d.com/ScriptReference/AI.NavMeshBuilder.BuildNavMeshAsync.html

    This method exists. But i can't seem to access it ? It simply is not something that exists when i try to access it.

    I am really confused why unity is half-assing the navmesh component systems. Is it abandon ware? Whats going on here, why is this stuff so poorly documented, and only available on git hub not even the package manager? It's really annoying me because its almost forcing me to buy an expensive asset or just use unreal at this point.

    Has any one been able to use it ? I don't know why i can't access it.
     
  2. adriant

    adriant

    Unity Technologies

    Joined:
    Nov 1, 2016
    Posts:
    31
    Later edit: As it was pointed out, the correct namespace is UnityEditor.AI .

    The method you are looking for is in the UnityEngine.AI namespace. You can call it using
    UnityEngine.AI.NavMeshBuilder.BuildNavMeshAsync()
    . A short note has been recently added to the 2018.3 documentation in order to clarify which methods are in the UnityEngine.AI namespace and which ones are in the UnityEditor.AI namespace. https://docs.unity3d.com/2018.3/Documentation/ScriptReference/AI.NavMeshBuilder.html

    The NavMesh components are the way to go forward. Although they haven't been turned into a package yet, they are and will be fully supported and ultimately they will be delivered as a package.
     
    Last edited: Sep 21, 2018
  3. PixelizedPlayer

    PixelizedPlayer

    Joined:
    Feb 27, 2013
    Posts:
    410

    Well i wanted to use NavMeshSurface but it doesn't call the async build version. So its not really the way to go.

    This isn't true though ? The only place it seems to exist is under the editor only code.

    See here:


    Under UnityEngine.AI.NavMeshBuilder, it does not have an async method.

    See here:


    This is what i am saying about the way Unity is handling these components, it's so confusing and the documentation isn't even correct. It all seems a bit of a mess. I am really confused by it all since it was announced in unity 5 but its almost like you guys have abandoned it half completed.
     
  4. adriant

    adriant

    Unity Technologies

    Joined:
    Nov 1, 2016
    Posts:
    31
    Oh, right. I've mixed them up myself. Sorry for that. I was trying to remember them from the top of my head without checking. The 2018.3 documentation indicates the right namespace though. It's
    UnityEditor.AI.NavMeshBuilder.BuildNavMeshAsync()
    .

    The runtime method you would want to use for async operations is
    UnityEngine.AI.NavMeshBuilder.UpdateNavMeshDataAsync
    . The data must first be created with
    UnityEngine.AI.NavMeshBuilder.BuildNavMeshData()
    and then it can be passed into the UpdateNavMeshDataAsync method.

    From the Editor UI the NavMeshSurface builds the NavMesh asynchronously. It uses the previously mentioned pattern. Please have a look at the code starting at this line https://github.com/Unity-Technologi...omponents/Editor/NavMeshSurfaceEditor.cs#L311 .
    To get the same thing at runtime first call
    navMeshSurface.BuildNavMesh()
    . This creates the NavMeshData object and builds the NavMesh once. Afterwards you can call
    navMeshSurface.UpdateNavMesh( navMeshSurface.navMeshData )
    every time you want to update the NavMesh.
     
  5. PixelizedPlayer

    PixelizedPlayer

    Joined:
    Feb 27, 2013
    Posts:
    410
    Okay thank you for clarifying.

    Will you guys be able to add Async for navMeshSurface.BuildNavMesh() because that seems to call the non async version:
    Code (CSharp):
    1.  
    2. // NavMeshSurface.cs
    3. // Method : BuildNavMesh();
    4. // Line: 157
    5. var data = NavMeshBuilder.BuildNavMeshData(GetBuildSettings(),
    6.                     sources, sourcesBounds, transform.position, transform.rotation);
    Unless build async is deliberately only available for editor due to the namespace, which if so, is an unusual decision since async is quite useful for run time.
     
  6. adriant

    adriant

    Unity Technologies

    Joined:
    Nov 1, 2016
    Posts:
    31
    For the moment we will not add a
    navMeshSurface.BuildNavMeshAsync()
    method because all the runtime methods for achieving that purpose are already available and we leave it to the developers to write their own implementation. The InitializeBakeData() implemented here https://github.com/Unity-Technologies/NavMeshComponents/blob/af0ed70c649df4e3a5207be8a446348f641cec26/Assets/NavMeshComponents/Editor/NavMeshSurfaceEditor.cs#L356 gives an example how an initial empty NavMeshData object can be created. Then that object can be used to asynchronously update (generate) the NavMesh into it. In order to actually have that NavMeshData active into the world it then needs to be added tot the system with
    NavMesh.AddNavMeshData()
    , with an option to specify exactly the position and orientation.
    I've taken a note based on your suggestion that we should provide this Build async method by default.

    UnityEditor.AI.NavMeshBuilder.BuildNavMeshAsync()
    is restricted to only the Editor because of several reasons: it can only deal with the entire scene at once, it searches only for geometry marked as "Navigation static" and it only bakes for the default origin position (0,0,0) and up axis (0,1,0).
     
    Last edited: Sep 21, 2018