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 luckruns0ut · Apr 10, 2013 at 04:01 PM · errorpathfindingastar

Array index is out of range - A* Open list.

I've been trying to figure out what's wrong with this code for a long time now with no success, no matter what I've tried. I don't know why, but apparently the open node isn't in the grid when I know for a fact that it is.

I'll post the code on the Pastebin link below as it is fairly long.

http://pastebin.com/mDNG39AG

Look for line 148. Can someone please look over it and make sure there are no daft errors which I've not seen?

Thanks.

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 Dracorat · Apr 10, 2013 at 04:09 PM 1
Share

I'd start by putting a debug statement on the line before and output the values of those x and z values.

avatar image whydoidoit · Apr 10, 2013 at 04:11 PM 1
Share

Ok given we know that the grid is complete (because you are drawing it, right?) $$anonymous$$y first thought would be that there's something screwy going on with the .Contains() using Vector3s as perhaps they aren't co$$anonymous$$g out equal. For my implementation of a grid I used a class containing three ints to represent positions so that comparisons are more likely to succeed.

avatar image whydoidoit · Apr 10, 2013 at 04:11 PM 1
Share

Also are you getting exceptions in all those empty catch blocks in your GetAdjacentNodes function? Exceptions are performance costly...

avatar image whydoidoit · Apr 10, 2013 at 04:12 PM 1
Share

I guess a try catch around 148 with a debug log showing the values of .z and .x would help narrow it down...

avatar image luckruns0ut · Apr 10, 2013 at 04:16 PM 0
Share

I followed a tutorial for the a* algorithm and in the tutorial I was told to do the try catch, I'm fairly new to pathfinding however I understand the algorithm clearly. I'll try what you suggested and post the result...

Show more comments

2 Replies

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

Answer by Unitraxx · Apr 10, 2013 at 04:21 PM

I think the problem originates from building your grid.

line 215:

             gridWidth = Mathf.RoundToInt(bounds.size.x / gridSize);
             gridLength = Mathf.RoundToInt(bounds.size.z / gridSize);
            
             grid = new Node[gridWidth, gridLength];

Do you take in account the behaviour of RountToInt? (Because you don't use it anywhere else) and that the maximum index is one smaller than the size you give up? I'm thinking that you are just giving larger values than your max index.

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 luckruns0ut · Apr 10, 2013 at 04:25 PM 0
Share

It has to be an integer as you can't use a decimal with an index.

avatar image Unitraxx · Apr 10, 2013 at 04:29 PM 1
Share

Yeah sure, but at other points you always use a cast to int, ins$$anonymous$$d of RountToInt.

avatar image whydoidoit · Apr 10, 2013 at 04:33 PM 1
Share

FloorToInt might be a better choice though - it has consistent behaviour

avatar image
0

Answer by luckruns0ut · Apr 10, 2013 at 04:36 PM

I think I have found the problem, or at least one error: I was passing the x and z axes through the grid[,] and didn't think to realize that they can't be negative. Also, how can I modify the algorithm to check if a path is even possible because the game will just crash if there is no path available.

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 whydoidoit · Apr 10, 2013 at 04:41 PM 1
Share

When your open list is empty and you aren't at the destination then there is no path.

avatar image luckruns0ut · Apr 10, 2013 at 04:44 PM 0
Share

Thanks for the help again.

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

13 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

Related Questions

How to apply A* algorithm in C#? 2 Answers

Inaccurate A* Pathfinding Scan! 3 Answers

Lost in Pathfinding 1 Answer

How do I go about making a 2d platform enemy ai 1 Answer

[Arongranberg A * Pathfinding Project] How to move units without overlaping of them? 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