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 DayyanSisson · Dec 31, 2012 at 07:45 PM · nodeargumentoutofrangeexception

Strange ArgumentExceptionOutOfRange Error

I've written a script and in the script its looking up nodes sorted by rows and columns to find the adjacent nodes of the current node. I've put in checks to make sure that an ArgumentExceptionIsOutOfRange error doesn't happen, and its never happened before, but now it is. I created two variables: row and column, which is the row/column of the current node. Then when searching for the nodes, I created a check to make sure that it wasn't searching for nodes that weren't there:

 if(column > 0){
 if(row < numberOfRows){
 if(column < numberOfColumns){
 if(column > 0 && row < numberOfRows){

etc....

But what's happening is that the out of range error is occurring on these lines:

 if(row < numberOfRows){
     Node down = nodes[column].nodes[row+1];
     if(down.node.gameObject.layer == 11 && !closedTransforms.Contains(down.node)){

and:

 if(column < numberOfColumns){
     Node downRight = nodes[column+1].nodes[row+1];
     if(downRight.node.gameObject.layer == 11 && !closedTransforms.Contains(downRight.node)){

(Note: the second block of code is under the if(row < numberOfRows){ statement).

It shouldn't be giving me an error because it checks to see if the row is less then the number of rows, which means if the number of rows is 10, the rest of the code will only execute if the row is 9, 8, 7..... which means that when I do [row+1], the biggest number it could give me is 10....which is the number of rows, which shouldn't be a problem. There are many other statements like this and none of them are giving me errors except for these two. So I ran debugs to check to see if the number of nodes in each row was the same as the numberOfRows variable and the same for numberOfColumns and it all matches and up. Its sometimes giving me errors like this where it says the column is out of range when the column is searching for is 6 and the actual number of columns is 12. What could possibly be wrong?!?

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 Dave-Carlile · Dec 31, 2012 at 09:37 PM

Arrays are 0 based, which means an array with 10 elements has indexes from 0 to 9. So, in your example, when row + 1 = 10 then you are indeed trying to access an invalid array element.

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 DayyanSisson · Dec 31, 2012 at 09:55 PM 0
Share

Oh yes, thats right, I didn't take that into consideration. Thanks!

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

9 People are following this question.

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

Related Questions

Rows and columns of buttons in a for loop 1 Answer

"Instantiating" GUI.Window in Editor 2 Answers

How can I detect changes to GraphView, Nodes and Edges? 1 Answer

ArgumentOutOfRange error with list 1 Answer

About the row major,CG really use row major? 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