Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 GutoThomas · May 11, 2012 at 05:34 PM · pathfindingwhilebreak

Problem with loop the get better path to goal

Hey everyone, I'm slowly trying to acquire some results with path finding and started reading some articles of A* to get a base. I don't know if I'm in the right path but I've reached this. (if you guys want the whole code I can post it here, i just didn't because I coded it in portuguese and take me a lot to translate).

The problem in the function below is that it's breaking Unity. Probably because of the loop.

What 'hasClearPath' does is basically launch a Linecast from the position of the last node of the list to the goal.

 public void findBestPath() {
             
             closedList.Clear();
             
             betterPath.Clear();
         
             openList = Nodes;
             
             betterPath.Add( findFirstNode() );
             
             while(true) {
                 
                 List<Nodes> Neighbors = findNeighbors( betterPath[betterPath.Count - 1] ); // returns a list of neighbors of the last item in betterPath
                 
                 betterPath.Add( findBetterNeighbor( Neighbors ) ); // find the better neighbor( lowest F) between Neighbors returned above and add him to the list
                 
                 if(betterPath[betterPath.Count - 1].hasClearPathTo(Goal)) { // if the last item of betterPath has clear path to the goal, breaks the loop
                     
                     break;
                     
                 }
                 
             }
             
             
         }

Any hint on this?

Thanks from now!

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

1 Reply

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

Answer by Berenger · May 12, 2012 at 05:34 AM

Well, the while true is not going to do any good there. It makes sense when you use it in a coroutine which is paused every frame or x seconds, but there your code juste get stucked inside the loop. So yield null or find a way to leave the loop at some point.

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 GutoThomas · May 13, 2012 at 01:07 PM 0
Share

Yeah. I wasn't sure about the use of while(true). I also tried while(Physics.Linecast(betterPath[betterPath.Count - 1].position, Goal.position)) but I get stucked in the loop too. What's the better way to get out of the loop in this case? I also try to check if the goal node is inside the closedList and then break the loop, but it breaks Unity.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

A* Pathfinding Bugs 0 Answers

A While Loop in a path finding system is freezing, how can I fix this? 0 Answers

Anyone help with an infinite loop problem on a while list.count >0 condition 2 Answers

NavMeshAgent Different Sizes Help 0 Answers

Unity2D Grid A* pathfinding freezing for a few seconds 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