Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. The 2022.2 beta is now available for testing. To find out what's new, have a look at our 2022.2 feature highlights.
    Dismiss Notice
  3. We are updating our Terms of Service for all Unity subscription plans, effective October 13, 2022, to create a more streamlined, user-friendly set of terms. Please review them here: unity.com/legal/terms-of-service.
    Dismiss Notice
  4. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice
Dismiss Notice
Submit bug reports tagged with #Beta2022Win_Unity when you encounter unknown issues while testing the 2022.2 betas for a chance to win a year of Unity Pro. For more information, have a look at our Beta Sweepstakes Announcement.

Asynchronous Navmesh Query Without Agent?

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

  1. BTables

    BTables

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