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 /
avatar image
0
Question by Wenon · Jun 15, 2018 at 09:29 AM · arrayindexout of range

Array index out of range after build

Hello, In editor works good but after build there is error IndexOutOfRangeException: Index was outside the bounds of the array.

                 int rand = Random.Range(0, (cars.Length));
                 vehicle = Instantiate(cars[rand]);

I tried with cars.length-1 too but not working. There is only one element in cars array but will be more but at this time I want to make it works with one element in the array. Why in editor it works but not after build?

Comment
Add comment · Show 9
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 Hellium · Jun 15, 2018 at 09:34 AM 0
Share

Are you sure cars.Length is greater than 0 in the build? How do you populate the array? Can you:

  1. Add a Debug.LogError(cars.Length); before calling Random.Range

  2. Open your build settings

  3. Check the Development build option

  4. Build your game

  5. See what the console outputs

avatar image Wenon Hellium · Jun 15, 2018 at 09:53 AM 0
Share

outputs 0, but why, arrays have prefabs, they do not reset when the game is turned on in editor, why do they reset after build?

avatar image Feelnside Wenon · Jun 15, 2018 at 11:24 AM 0
Share

Try to move your prefabs into the "Assets/Prefabs" folder. $$anonymous$$aybe they are located in some unexpected folder and as result they do not included into the final build.

Show more comments
Show more comments
avatar image pcdrive · Jun 15, 2018 at 10:27 AM 0
Share

Can it happen, that the array is not existing at all? I run into same problems like, you create the variable like this: 'GameObject[] cars', and then the program goes a way where it gets no value at all. since its an array it will let you use the [] call, but throws an exception even for the 0 value.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Wenon · Jun 15, 2018 at 05:04 PM

Please can anyone help me with arrays which resets after build with no reason?

Comment
Add comment · 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

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

103 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 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 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 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 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 avatar image avatar image avatar image

Related Questions

How do I check a List[0], when it's nothing? 1 Answer

Array index is out of range Error, only when array is used to Instantiate 4 Answers

How to check if a c# 3d array index exists? 1 Answer

Out of range error 1 Answer

IndexOutOfRangeException: Array index is out of range. 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