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 yoger · Jan 21, 2014 at 05:09 PM · c#pathfindingfreeze

A* freezes unity

I'm trying to learn about pathfinding, right now I'm getting unity freezed at second iteration. Here's the part which freezes (it goes fine at the first time) so if you can't spot any problems in this function I'll post some more, maybe problem is somewhere else.

 private Node GetByPosition(Vector3 pos, Dictionary<int, Node> d){
         Node m = null ;
         print("checking");
         foreach(KeyValuePair<int, Node> n in d){
             if(n.Value.position == pos){
                 m = n.Value;
             }
         }
         
         if(m == null)
             print ("No Node in dict");
         
         
         return m;
     }
Comment
Add comment · Show 2
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 Ferb · Jan 21, 2014 at 07:24 PM 0
Share

I don't see any problem with that code. If it goes fine the first time you search but not the second, is it possible you aren't clearing the Dictionaries or resetting certain flags in between searches? $$anonymous$$aybe that causes the condition of a loop somewhere never to get satisfied. $$anonymous$$nowing how full the dictionary is when this function gets called, compared to how full you'd expect it to be, would be useful too.

avatar image yoger · Jan 21, 2014 at 07:47 PM 0
Share

I have added conditional statement to check if dictionary contains any records before going through it, but it doesn't change anything and this method returns null if there's no hits anyway so I'll just post the main loop:

 while(open.Count > 0 && failsafe > 0){ //While we have something in open dictionary
             yield return new WaitForSeconds(.5f);
             failsafe--;
             current = Pick(open);                //Set current node to best choice from open dictionary
             
             RemoveByValue(open, current);        //Remove current from open
             Place(closed, current);                //and place it in closed
             
             if(current.position == target){
                 StartCoroutine("GeneratePath", current);            //When target is reached, break loop and generate path from the last element
                 break;
             }
             
             GameObject tmp2 = (GameObject)Instantiate(player, current.position, Quaternion.identity);
             tmp2.renderer.material.color = Color.yellow;
                         
             gScore = current.cost;
             foreach(Node n in GetParentNodes(current)){
             print ("Open: " + open.Count + " Closed: " + closed.Count + " For: " + current.position.ToString());
                 if(n != null){
                     if(obstacles.ContainsValue (n.position) == false){
                         GameObject tmp = (GameObject)Instantiate(player, n.position, Quaternion.identity);
                         tmp.renderer.material.color = Color.green;
                         float estmationOfGscore = current.cost + n.cost;
                         yield return new WaitForSeconds(.5f);
                         
                         Destroy(tmp,0);
                         print("Check n.pos " + n.position);
                         yield return new WaitForSeconds(.5f);
                         
                         if(GetByPosition (n.position, closed) != null)
                             continue;
                             
                         if(GetByPosition (n.position, open) == null && GetByPosition (n.position, closed) == null){
                             //print ("move to open");
                             n.cost = current.cost + 1;
                             n.fScore = n.cost + Heuristic(n);
                             n.previous = current;
                             Place (open,n);
                         }
                     }
                 }
             }
             Destroy(tmp2,0);
         }

1 Reply

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

Answer by HappyMoo · Jan 21, 2014 at 10:26 PM

Are you going into an infinite Loop? Debug your program to see why.

Set Breakpoints in MonoDevelop and Run-Menu -> AttachToProcess

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 yoger · Jan 22, 2014 at 05:00 AM 0
Share

Thanks mate! That helped me to resolve mystery. I would never expecte that the reason could be trying to place a random number as a key (max random value was a little bit high) if default key already existed when adding new node to dictionary!

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

20 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

A* Pathfinding Project Y-axis movement, help. 1 Answer

How do I implement A* pathfinding to my 2d game, without tiles? 4 Answers

A* endless loop 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