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 gunespedastrian · Aug 28, 2015 at 12:35 PM · errorargumentoutofrangeexceptionarray-out-of-range-except

ArgumentOutOfRangeException: Argument is out of range. Parameter name: index

That error really like an annoying kid. First I tried

 public string[] debugstrings;
 
 

and when I do this;

  debugtext.text = debugstrings[1];

I want to delete first element of array. But why I don't know C# doesn't supports the normal array functions like RemoveAt(); And I tried with ;

 public System.Collections.Generic.List<string> debugstrings;

That works perfectly. But when I want

 debugtext.text = debugstrings[1];

There are an error.. :'<

 ArgumentOutOfRangeException: Argument is out of range.
 Parameter name: index
 System.Collections.Generic.List`1[System.String].get_Item (Int32 index).....


Why this happening and what is this. Why unity doesn't make any real solution for arrays? Thats a small thing and I must focus other important things. But why I must get an error every time? Why this happens..? Please help..

Comment
Add comment · Show 3
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 Positive7 · Aug 28, 2015 at 12:50 PM 1
Share

With the list method it should work fine. At least it does here :

  using UnityEngine;
     using UnityEngine.UI;
     
     public class test3 : $$anonymous$$onoBehaviour {
         public System.Collections.Generic.List<string> debugstrings;
         public Text debugtext;
         
         void Start(){
             debugtext.text = debugstrings[1];
             debugstrings.RemoveAt (1);
         }
     }
 

   

And it's possible to do the same with

 public string[] debugstrings;

but it requires a bit more coding.

avatar image gunespedastrian · Aug 28, 2015 at 01:08 PM 0
Share

@Positive7

I know but when I do that ı get the same error.

 That error really like an annoying kid. First I tried
 
  public string[] debugstrings;
  
  
 and when I do this;

I wrote here its easiest way but there is no support for real functions like RemoveAt();

avatar image unbelievablename · Aug 28, 2015 at 01:21 PM 0
Share

$$anonymous$$aybe, the array is empty.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by pgomes · Aug 28, 2015 at 01:33 PM

Make sure you always initialize your builtin arrays before using them:

 debugstrings = new string[<IMMUTABLE-SIZE>];

In C# you can't resize builtin arrays. From the documentation:

There are two types of arrays in Unity, builtin arrays and normal Javascript Arrays. Builtin arrays (native .NET arrays), are extremely fast and efficient but they can not be resized

Use a mutable size container instead, such as a List.

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 Positive7 · Aug 28, 2015 at 02:20 PM 1
Share

That's not interly true using System;

 Array.Resize(ref myArray, newSize);


Should do the trick.I can't write an example at the moment. I'll do it later tho. :P

avatar image pgomes · Aug 28, 2015 at 02:36 PM 0
Share

System.Array is a mutable size container and it is not what the documentation defines as builtin array. I would continue to argue that if you are going to be removing elements from debugstrings you might be better off with a List. For pros and cons check http://stackoverflow.com/questions/434761/array-versus-listt-when-to-use-which#comment27660729_434761

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

29 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

Related Questions

Argument Out of Range Exception: Error with Array Turned into List 0 Answers

I am getting an error : ArgumentOutOfRangeException: Argument is out of range. Parameter name: index 0 Answers

IndexOutOfRangeException: Index was outside the bounds of the array. (wrapper managed-to-managed) System.Object.ElementAddr_4(object,int,int,int) 0 Answers

Argument out of Range Exception Error. [Basic] 0 Answers

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