Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by KazyX · Nov 13, 2015 at 09:53 PM · inspectorarraylist

IndexOutOfRangeException at 0

I been getting the error "IndexOutOfRangeException: Array index out of range"

However I don't know why. The revelant code is:

 // Variables
  public Transform target; //Where I want the object to move
  public Transform[] EndPoint; //List of possible positions, on the Inspector I set it to a size of 9 and fill every slot with an object
 
 void Start() {
  int i = Random.Range(0,9) ;
  target = EndPoint [i] ;
 }

Once I play I get the mentioned error. BUT I can see on the inspect that target has changed into one of the possible endpoints. If I ignore the error and resume the game it even works as intended and the object moves to position.

I have even tried removing the randomness out of the equation and instead using 'target = EndPoint[0]' but just as above, it still gives me an error.

While searching for an answer some people suggested resetting the script values in the inspector, which I did to no avail.

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 Jessespike · Nov 13, 2015 at 10:35 PM 1
Share

If the list of Transforms is filled in the Inspector before playing. Then this should be working without any errors. I'm thinking you accidentally placed the script on another GameObject and it's that empty list of Transforms that is throwing the error. In your project, right-click on the script and select "Find References In Scene". $$anonymous$$aybe you'll find something.

avatar image KazyX Jessespike · Nov 14, 2015 at 12:24 AM 0
Share

You're correct!

Checked all of my GameObjects and found the extra copy of the script. Now its working fine, thank you : D

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by bubzy · Nov 13, 2015 at 11:27 PM

try 0-8, like int i = Random.Range(0,8);

if you have an array of size 9 it will be number range 0-8 thus making 9 elements.

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 KazyX · Nov 14, 2015 at 12:27 AM 0
Share

When dealing with int, the second value is exclusive. But I appreciate the help!

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Why i can't see scenes in inspector? 0 Answers

Inspector will not open 1 Answer

Inspector assigned variables not assigning in build 0 Answers

Unity 4.1.5 is not showing certain public variables in the inspector 1 Answer

Inspector List: DropDown list Update regarding Prefab in asset folder 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