Search Unity

Why is there no non-blocking pathfinding? What am I missing?

Discussion in 'Navigation' started by Tyrathect, Dec 3, 2016.

  1. Tyrathect

    Tyrathect

    Joined:
    Jul 10, 2012
    Posts:
    38
    Here's my issue:

    I have an agent moving along a path from point A to point B. When it gets to point B, it's going to want to navigate to point C. I want to calculate the path from B to C before the agent gets to B so that the agent doesn't pause at B waiting for the path, and so that the agent's heading can smoothly turn from the A->B path to the B->C path.

    Unfortunately, this simple functionality does not seem to be possible with Unity, because there doesn't appear to be a way to get an arbitrary path without blocking.

    You guys provide the NavMeshAgent.CalculatePath() to create a path without automatically starting to follow it, but the starting point of that path is always the current position of the transform. I need to start the path from a different location (position B). What is the intended use of this function? It doesn't seem to have a practical use. More specifically, it seems artificially limited to only be useful in a few very specific cases. Why isn't there a version that takes a starting location?

    You also provide the NavMesh.CalculatePath() which blocks and can't be called from a thread. This makes it useless in a large or complicated level. What is the intended use? Why didn't you guys add a non-blocking version?

    I could put a NavMeshAgent component on an otherwise empty game object and move that around and use it to calculate paths, but the other NavMeshAgents (which are attached to actual AI's) would avoid it, and there's no way to turn that off (as far as I can tell).

    So, what am I missing? This is such a glaring error, and seems so easy to fix that I feel like I must be missing something.

    You have this reasonable navigation system which can't really be used efficiently.
     
  2. Kylotan

    Kylotan

    Joined:
    Feb 17, 2011
    Posts:
    212
    How about creating an invisible NavMeshAgent at position B? Then take that agent's path once the original one reaches that position. You could even use NavMeshAgent.SetDestination to do it asynchronously, and leave updatePosition as false so it doesn't start moving.
     
  3. Tyrathect

    Tyrathect

    Joined:
    Jul 10, 2012
    Posts:
    38
    @Kylotan: because the other NavAgents will avoid the invisible one.
     
  4. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,518
    Can't you just use NavMeshAgent.CalculatePath?

    edit: duh, nevermind.. I havent had coffee yet.
     
  5. Tyrathect

    Tyrathect

    Joined:
    Jul 10, 2012
    Posts:
    38
    I guess you guys aren't reading my post completely. @LaneFox: CalculatePath only calculates a path from the NavAgent's current position. You have to put it in the world for it to work, which means other nav agents will try to avoid it.
     
  6. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,518
    Yeah, sorry I'm on my first cup of joe this morning. *facepalm*

    tbh the build-in Nav/Agent stuff is decent for basic things but lacks a lot of more necessary advanced features so you might be better off just looking at something like Apex sooner than later.
     
  7. Tyrathect

    Tyrathect

    Joined:
    Jul 10, 2012
    Posts:
    38
    lol, np. I've looked at some of the other solutions on the asset store, but my experience with asset store assets has been disappointing. Do you have experience with Apex?

    I'm also disappointed because this unity feature (like most others) is close to being good. It has enough functionality to be impressive in demos, but flaws in the design and / or API that keep it from being usable at scale.
     
  8. Jos-Yule

    Jos-Yule

    Joined:
    Sep 17, 2012
    Posts:
    292
    As a total hack, you can create a GameObject, with a NavMeshAgent on it, with a priority level that all other NavMeshAgents ignore it for local avoidance. Use this as a "placeholder" for whatever non-my-current-location pathfinding you need. keep a reference to it from wherever, move it to where you need it, then run the pathfinding commands/methods you need. Maybe?
     
  9. Tyrathect

    Tyrathect

    Joined:
    Jul 10, 2012
    Posts:
    38
    This is a horrible hack, but a great idea! I'll give this a try. Thanks!