Search Unity

  1. Are you interested in providing feedback directly to Unity teams? Sign up to become a member of Unity Pulse, our new product feedback and research community.
    Dismiss Notice

Asynchronous Navmesh Query Without Agent?

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

  1. BTables

    BTables

    Joined:
    Jan 18, 2014
    Posts:
    58
    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

    Claytonious

    Joined:
    Feb 16, 2009
    Posts:
    732
    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.
unityunity