Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. We are looking for your feedback about Templates! Tell us about your experiences by taking our survey.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

How to know if a given destination point is valid before call SetDestination?

Discussion in 'Navigation' started by ptr0x, Mar 14, 2015.

  1. ptr0x

    ptr0x

    Joined:
    Dec 9, 2013
    Posts:
    51
    Hello,

    In the navmesh system is there a way to know if the destination point have a valid path before (or at least in the same frame) a call to NavMeshAgent.SetDestination?

    I send a network packet when the client moves around the map, but I can only send the packet if the movement is valid.

    Thanks.
     
  2. Smithy43

    Smithy43

    Joined:
    Sep 8, 2012
    Posts:
    9
    In order to determine if an agent can navigate to a position I think you have two options:
    1. Use NavMesh.CalculatePath to calculate a path between the source and destination points. This happens synchronously so you get the path back immediately and you can therefore determine its status without waiting (you can then set this path on the agent if you wish using NavMeshAgent.SetPath)
    2. Use NavMeshAgent.SetDestination and then wait until the path has been calculated to determine if it is valid or not (you can use a coroutine and wait until !NavMeshAgent.PathPending and then check NavMeshAgent.pathStatus once completed)
    I think the main benefit of option 2 is that the path is calculated in a separate thread so you may get a performance benefit.
     
  3. ptr0x

    ptr0x

    Joined:
    Dec 9, 2013
    Posts:
    51
    Thank you very much.
     
  4. Jakob_Unity

    Jakob_Unity

    Unity Technologies

    Joined:
    Dec 25, 2011
    Posts:
    269
unityunity