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 EBBAzores · Aug 27, 2015 at 01:13 PM · c#scripting problemconnectionarray-out-of-range-except

How to solve "Array Index is out of range"

I'm developing a project on Unity where I want to make an app that connects Neurosky's Mindwave Mobile with Sphero. Essentially Mindwave Mobile sends brainwave signalls to the app as input and the app sends as output information for the Sphero robot to move.

However, Neurosky helps by making avaiable an example of a project using Mindwave Mobile to work on. In the example theres a demo and the demo, when I try to run it, it keeps getting me this error:

 IndexOutOfRangeException: Array index is out of range.
 DisplayData.OnGUI () (at Assets/NeuroSkyAssets/NeuroSkyScripts/DisplayData.cs:125)

Which is associated with this code line:

 line 6: public Texture2D[] signalIcons;
 line 8: private float indexSignalIcons = 1;
 line 52: void OnUpdatePoorSignal(int value){
         PoorSignal = value;
         if(value == 0){
               indexSignalIcons = 0;
             enableAnimation = false;
         }else if(value == 200){
               indexSignalIcons = 1;
             enableAnimation = false;
         }else if(!enableAnimation){
             indexSignalIcons = 2;
             enableAnimation = true;
         }
 line 64:    }
 
 line 111: void FixedUpdate(){
         if(enableAnimation){
             if(indexSignalIcons >= 4.8){
                 indexSignalIcons = 2;
             }
             indexSignalIcons += animationInterval;
         }
         
 line 119:    } 
 
 line 121: void OnGUI(){
         GUILayout.BeginHorizontal();
         GUILayout.Label("Demo App");
         GUILayout.Space(Screen.width-250);
 line 125:GUILayout.Label(signalIcons[(int)indexSignalIcons]);
         GUILayout.EndHorizontal();

This is every code apart I'm guessing that is associated with the error. What should I do?

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 · Aug 27, 2015 at 01:50 PM

How large is the signalIcons array? Have you assigned textures to it? How many?

The code you show is deciding which texture to display based on various things. It calculates and stores the value using indexSignalIcons which is used as an index into the signalIcons array. The value it's calculating is either negative (which doesn't appear to be the case) or it's larger than the number of textures stored in the array.

To fix this, you need to either add all of the expected icons to the array, or figure out why the calculated index isn't calculating properly. To help with the latter you can check the index before using it and log a message with the value if it's out of range. In OnGUI, before line 125...

 if (indexSignalIcons < 0 || indexSignalIcons >= signalIcons.Length)
 {
   Debug.Log("Signal Icon Index is out of range: " + ((int)indexSignalIcons));
 }
 else
 {
   GUILayout.Label....
 }
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

27 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

Related Questions

How can I make a C# sharp script execute in a certain order? 1 Answer

How to add a editing option to variables in a script in Inspector? 0 Answers

How to create buttons with script? 0 Answers

Side-scrolling Enemy AI not shooting in the right direction 0 Answers

How to make a random object generator that responds to simple touch? 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