Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by $$anonymous$$ · May 10, 2016 at 02:00 PM · c#ainavmeshnavigationnav mesh

How to know if a NavigationMeshAgent is impossible to reach Destination

I’m wondering to know if there is some way to get TRUE or FALSE, if the NavigationMeshAgent will never reach the destination point.

(I want to know it from the beggining, not when the object velocity is 0,0,0)

(c# if is possible)

Thanks a lot if someone knows.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by YoungDeveloper · May 10, 2016 at 02:11 PM

I believe CalculatePath http://docs.unity3d.com/ScriptReference/NavMeshAgent.CalculatePath.html retuns bool which represent if the path can be calculated - exists. You can't be sure about dynamic obstacles though.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image $$anonymous$$ · May 11, 2016 at 02:19 PM 0
Share

Thanks, finally found "pathPending" does it

avatar image
-1

Answer by $$anonymous$$ · May 11, 2016 at 02:20 PM

This works fine:

 if (this.transform.GetComponent<NavMeshAgent> ().pathPending) {
             Debug.Log ("False");
         } else {
             Debug.Log ("True");
         }
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image insominx · May 11, 2016 at 03:42 PM 0
Share

This does not answer the question and pathPending will often be true during the first few frames after calling SetDestination. See Ta$$anonymous$$g the Unity Navigation System for more details.

avatar image
0

Answer by insominx · May 11, 2016 at 03:49 PM

As mentioned by YoungDeveloper, CalculatePath will give you a result immediately after calling it with the information you're after. Here's some sample code from the documentation:

 using UnityEngine;
 using System.Collections;
 
 public class ExampleClass : MonoBehaviour {
     public Transform target;
     private NavMeshAgent agent;
     void Start() {
         agent = GetComponent<NavMeshAgent>();
         NavMeshPath path = new NavMeshPath();
         agent.CalculatePath(target.position, path);
         if (path.status == NavMeshPathStatus.PathPartial) {
         }
     }
 }


However if you're using SetDestination, you may have to wait a few frames for an answer and the method will be similar. Like before, you check the path status only with the exception that you have to wait for pathPending to be false (otherwise Unity may still be calculating it).

See here for more details: Taming the Pathfinding System

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image $$anonymous$$ · May 11, 2016 at 04:20 PM 0
Share

Thank you for help, as i'm sure you know more than me Iv'e changed my comment as not valid answer.

Even though, your comment does not help me as I wish. Don't understand how can I use this code sample.

avatar image insominx $$anonymous$$ · May 11, 2016 at 05:02 PM 0
Share

If you're using CalculatePath then the return value will tell you what you want to know. True if there is a path and false if there isn't. I include it for people using SetDestination who will need to check the value of status and pathPending in order to know.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

154 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Navmesh Agent "move back" when player comes to close? 1 Answer

NavMeshPath.corners.length is always 0 1 Answer

Make a flying enemy ? 0 Answers

Navmesh agent forward movement 1 Answer

How to make NavMeshAgents traverse two possible paths 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges