• 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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
1
Question by starikcetin · May 31, 2015 at 08:51 PM · c#navmeshnavmeshagentpathfinding

SetDestination's and CalculatePath's Path State Return Works Too Late

Hi all, I'm trying to make a turret defence game. And i'm trying to check if my navmesh agent can reach to target if i place the turret on selected grid by using bool return of SetDestination. The problem is, it reports that path is blocked when i try to place another turret after i placed the turret actually blocking path. Below is my placement function of turret placement script.

Edit: I tried with both SetDestination and CalculatePath. Nothing changed, below is the one i tried with CalculatePath.

Thanks in advance.

     void GhostComeAlive ()
     {
         aGridSelected = false;
 
         //first create a temporary gameobject to check if path can complete itself.
         GameObject gridToCheck = lastGridMousePassedOver;
         GameObject navMeshCheckerTemp = Instantiate(GhostTurretG, gridToCheck.transform.position, gridToCheck.transform.rotation) as GameObject;
         GameObject navMeshChecker = Instantiate(navMeshCheckerTemp, navMeshCheckerTemp.transform.position, navMeshCheckerTemp.transform.rotation) as GameObject;
         Destroy (navMeshCheckerTemp);
 
         //calculate the path.
         NavMeshPath path = new NavMeshPath();
         navMeshValidator.GetComponent<NavMeshAgent>().CalculatePath(navMeshTarget.transform.position, path);
 
         //now check if it's valid.
         if (path.status == NavMeshPathStatus.PathComplete)
         {
             Debug.Log ("Path is valid");
 
             //it's valid. let the temporary turret to remain and relase the global object.
             Destroy(GhostTurretG);
             GhostTurretG = null;
 
             //delete the grid from available grid's list.
             listOfGridsAvailable.Remove(gridToCheck);
 
             //destroy the grid.
             Destroy(gridToCheck);
         }
         else
         {
             Debug.Log ("Path is not valid");
 
             //it's invalid. destroy the temporary turret and let global object to remain.
             Destroy(navMeshChecker);
         }
 
         lastGridMousePassedOver = null;
         aGridSelected = false;
     }
 




Comment
Add comment · Show 7
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 cjdev · May 31, 2015 at 08:57 PM 1
Share

Have you tried Nav$$anonymous$$esh.CalculatePath?

avatar image starikcetin · May 31, 2015 at 09:45 PM 0
Share

I'm trying now but, will it actually change anything? If so, then we will be found a bug in SetDestination, aren't we?

Edit: nothing changed, still same thing.

avatar image starikcetin · Jun 01, 2015 at 05:08 PM 0
Share

Any answers?

avatar image tanoshimi · Jun 01, 2015 at 05:56 PM 0
Share

Your question is somewhat hard to follow. Can you strip down your code to something that succinctly demonstrates your problem?

avatar image starikcetin · Jun 01, 2015 at 07:40 PM 0
Share

I will try to. Thanks for reply.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer Wiki

Answer by starikcetin · Jun 05, 2015 at 11:45 PM

Allright, this solved the problem, temporarily... Cause I overload "WaitForEndOfFrame"s.

     IEnumerator GhostComeAlive ()
     {
         aGridSelected = false;
 
         //first create a temporary gameobject to check if path can complete itself.
         GameObject gridToCheck = lastGridMousePassedOver;
         GameObject navMeshChecker = Instantiate(GhostTurretG, gridToCheck.transform.position, gridToCheck.transform.rotation) as GameObject;
 
         yield return new WaitForEndOfFrame();
         yield return new WaitForEndOfFrame();
         yield return new WaitForEndOfFrame();
         yield return new WaitForEndOfFrame();
         yield return new WaitForEndOfFrame();
         yield return new WaitForEndOfFrame();
 
         //calculate the path.
         NavMeshPath path = new NavMeshPath();
 //        navMeshValidator.GetComponent<NavMeshAgent>().CalculatePath(navMeshTarget.transform.position, path);
 //
 //        //now check if it's valid.
 //        if (path.status == NavMeshPathStatus.PathComplete)
         NavMesh.CalculatePath(navMeshValidator.transform.position, navMeshTarget.transform.position, NavMesh.AllAreas, path);
 
         yield return new WaitForEndOfFrame();
         yield return new WaitForEndOfFrame();
         yield return new WaitForEndOfFrame();
         yield return new WaitForEndOfFrame();
         yield return new WaitForEndOfFrame();
         yield return new WaitForEndOfFrame();
 
         if (path.status == NavMeshPathStatus.PathComplete)
         {
             Debug.Log ("Path is valid");
 
             //it's valid. let the temporary turret to remain and relase the global object.
             Destroy(GhostTurretG);
             GhostTurretG = null;
 
             //delete the grid from available grid's list.
             listOfGridsAvailable.Remove(gridToCheck);
 
             //destroy the grid.
             Destroy(gridToCheck);
         }
         else
         {
             Debug.Log ("Path is not valid");
 
             //it's invalid. destroy the temporary turret and let global object to remain.
             Destroy(navMeshChecker);
         }
 
         lastGridMousePassedOver = null;
         aGridSelected = false;
     }
 }
 
Comment
Add comment · Show 3 · 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 starikcetin · Jun 11, 2015 at 09:31 AM 0
Share

This code also caused the same problem now. Anyone has a solution out there? Or maybe i should change my game engine to unreal engine?

avatar image starikcetin · Jun 12, 2015 at 11:08 AM 0
Share

bump, still looking for solution.

avatar image starikcetin · Jun 12, 2015 at 04:12 PM 0
Share

It seems like there is no solution for this. I must change to Unreal Engine before it's too late. Thanks all though.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

is it possible to use navmesh on flying character and target ? 0 Answers

Looking forward while walking with navMeshAgent 1 Answer

Finding Closest Object Through Navmesh,Identifying Which Object Is Closest on NavMesh 0 Answers

Unity pathfinding - Comparing 2 paths? 2 Answers

Editing NavMesh Paths? 0 Answers


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