Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  3. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Asynchronous Navmesh Query Without Agent?

Discussion in 'AI & Navigation Previews' started by BTables, May 3, 2017.

  1. BTables


    Jan 18, 2014
    This is from a thread in the AI forum, wanted to post here for visibility:

    I am currently attempting to upgrade from AstarPathfinding project to 5.6 navigation. Can't seem to figure out how to query the navmesh without blocking or using a managed NavmeshAgent.

    This surprises me considering how awesome and flexible the Navmesh generation process is that the consumption of the Navmesh is confined to one non asynchronous method (Navmesh.CalculatePath) or a fully automated closed source agent.

    My use case is our AI is networked, and we query the Navmesh on the server to determine the path of the NPC for the next few seconds, then serialize only the list of corners across the network and traverse the path on both the client and server in a deterministic way perfectly in sync (Using an asset store plugin for the Navmesh query). This sends 1-2 transforms per second across the network vs position and rotation updates at 10hz for streamed positions.

    Doing a blocking calculate serverside isn't an option (my simple tests were returning upto 3ms sometimes)

    Seems like my options are:
    A) Creating a NavmeshAgent and setting its speed to 0 and hope the local avoidance, transform updates, and all the other features I don't want aren't causing too much overhead, further testing shows the agent always tries to own the transform position, only overridable in LateUpdate which may break navmesh ownership stuff.

    B) Try to do a setpath on a client side agent and let the server side agent replace our existing path traversal code

    Any insight would be helpful
    phobos2077 likes this.
  2. Claytonious


    Feb 16, 2009
    You can also turn off almost all of the agent's "autonomy" by doing this:

    Code (CSharp):
    1. _agent.updatePosition = _agent.updateRotation = _agent.updateUpAxis = false;
    And then periodically doing:

    Code (CSharp):
    1. _agent.nextPosition = transform.position;
    to "reset" the agent back to where your object actually is.

    None of this to say that you're wrong in wanting a simple way to calculate paths asynchronously without an agent!
    phobos2077 likes this.