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 jjesh · Mar 11, 2016 at 03:35 PM · arraylistmenusearchargumentoutofrangeexception

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

Hi, up until recently I had some code that was working fairly well. I'm not sure what I did, but now it's throwing an ArgumentOutOfRangeException and I have no idea what is causing it. Can anyone help me?

 using UnityEngine;
 using UnityEngine.UI;
 using System;
 using System.Collections;
 using System.Collections.Generic;
 
 public class SearchMap : MonoBehaviour {
     public float tagPercent = 80;
     private float inputRatio;
     private int q;
     private int b;
     private locationDatabase database;
     public List<Location> seenLocations = new List<Location>();
     public List<Location> newLocations = new List<Location> ();
     private List<Location> savedLocations = new List<Location> ();
     public List<string> tagList = new List<string> ();
     public string[] tagArray;
     public GameObject locListItem;
     public GameObject viewContent;
     public GameObject locMenu;
     public GameObject spawnItem;
     public GameObject curPip;
     public Transform pipHolder;
     public InputField iField;
     public string myName;
     public string tinyTag;
     public string[] tags;
     openLocation oLocation;
     public Sprite bluePip;
     public Sprite redPip;
     private bool tagLength;
     
 
 
     public void bounceName()
     {
 
         foreach(Transform child in pipHolder)
         {
             child.gameObject.SetActive(false);
         }
         myName = iField.text.ToLower ();
 
         foreach (Transform child in viewContent.transform) 
         {
             Destroy (child.gameObject);
         } 
         foreach (Location loc in database.locations) 
         {
             tagLength = false;
             tagArray = database.locations[b].locTags.Split(',');
             q = 0;
             foreach(string tag in tagArray)
             {
                 if(tagArray[q].Contains(myName) && (myName.Length * 1f)/(tagArray[q].Length * 1f) >= tagPercent/100)
                 {
                     Debug.Log(tagArray[q]);
                     tagLength = true;
                     break; 
                 }
                 q++;
             }
             Debug.Log("before suspect");
             Debug.Log(database.locations[b]);
             if ((!seenLocations.Contains (database.locations [b])) && savedLocations.Contains (database.locations [b]) && tagLength) 
             {  
                     seenLocations.Add (database.locations [b]);
                     Debug.Log("Added: " + seenLocations[b]);
                     b++;
             } 
 
             else if ((!seenLocations.Contains (database.locations [b])) && !savedLocations.Contains (database.locations [b]) && tagLength) 
             {
                     newLocations.Add (database.locations [b]);
                     Debug.Log("Added: " + newLocations[b]);
                     b++;
             }
             else
             {
                 b++;
                 Debug.Log("Went to C Round");
             }
             Debug.Log("Stuck at end of part I");
         }
         Debug.Log ("Made it end of part I");
         b = 0;
         foreach (Location loc in newLocations) {
             Debug.Log("In part 2");
             spawnItem = Instantiate (locListItem) as GameObject;
             spawnItem.transform.SetParent (viewContent.transform, false);
             spawnItem.transform.localPosition = new Vector3 (100, -39 - (70 * b), 0);
             oLocation = spawnItem.GetComponent<openLocation> ();
 
             oLocation.locName = newLocations [b].locName;
             oLocation.locAddress = newLocations [b].locAddress;
             oLocation.locDescription = newLocations [b].locInfo;
             oLocation.locScene = newLocations[b].locScene;
             oLocation.pipNumber = (b + 1).ToString();
             oLocation.newPip = true;
             oLocation.locMenu = locMenu;
 
             curPip = pipHolder.FindChild(newLocations[b].locName).gameObject;
             curPip.gameObject.transform.GetComponent<Image> ().sprite = redPip;
             curPip.transform.GetChild(0).GetComponent<Text>().text = (b + 1).ToString();
             curPip.transform.GetComponent<Pip>().listButton = spawnItem;
             curPip.SetActive(true);
             
             b++;
         }
         b = 0;
         foreach (Location loc in seenLocations) {
 
             spawnItem = Instantiate (locListItem) as GameObject;
             spawnItem.transform.SetParent (viewContent.transform, false);
             spawnItem.transform.localPosition = new Vector3 (100, -39 - (70 * (b + newLocations.Count)), 0);
             oLocation = spawnItem.GetComponent<openLocation> ();
 
             oLocation.locName = seenLocations [b].locName;
             oLocation.locAddress = seenLocations [b].locAddress;
             oLocation.locDescription = seenLocations [b].locInfo;
             oLocation.locScene = seenLocations[b].locScene;
             oLocation.pipNumber = (b + 1).ToString();
             oLocation.newPip = false;
             oLocation.locMenu = locMenu;
 
             curPip = pipHolder.FindChild(seenLocations[b].locName).gameObject;
             curPip.gameObject.transform.GetComponent<Image> ().sprite = bluePip;
             curPip.transform.GetChild(0).GetComponent<Text>().text = (b + 1).ToString();
             curPip.transform.GetComponent<Pip>().listButton = spawnItem;
             curPip.SetActive(true);
 
 
             b++;
 
         }
 
         b = 0;
         foreach (Location loc in seenLocations) {
             savedLocations.Add (seenLocations [b]);
             b++;
         }
         seenLocations.Clear();
 
         b = 0;
         foreach (Location loc in newLocations) {
             savedLocations.Add (newLocations [b]);
             b++;
         }
         newLocations.Clear();
 
         }
         
         //Debug.Log (myName);
 
 
     void Start()
     {
         database = GetComponent<locationDatabase> ();
     }
 
 }


The locations themselves just hold a bunch of strings, the last of which is a list of tags the player can search for, separated by commas. Here's the full error:

ArgumentOutOfRangeException: Argument is out of range. Parameter name: index System.Collections.Generic.List`1[Location].get_Item (Int32 index) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Collections.Generic/List.cs:633) SearchMap.bounceName () (at Assets/Scripts/testing/SearchMap.cs:75) UnityEngine.Events.InvokableCall.Invoke (System.Object[] args) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:149) UnityEngine.Events.InvokableCallList.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:626) UnityEngine.Events.UnityEventBase.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:766) UnityEngine.Events.UnityEvent.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent_0.cs:54) UnityEngine.UI.Button.Press () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:35) UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:44) UnityEngine.EventSystems.ExecuteEvents.Execute (IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:52) UnityEngine.EventSystems.ExecuteEvents.Execute[IPointerClickHandler] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction`1 functor) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:269) UnityEngine.EventSystems.EventSystem:Update()

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

Answer by jgodfrey · Mar 11, 2016 at 05:02 PM

That's a lot of code and not much detail on the problem. You need to post the full error message so we have some idea where the error is in the posted code...

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 jjesh · Mar 11, 2016 at 05:05 PM 0
Share

Woops, sorry! I just added it.

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

52 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

Related Questions

Unknown Argument Out of Range Index Error On Card Game 1 Answer

Why is argument out of range? 1 Answer

How to compress iterative code, perhaps using a list and/or loops? 1 Answer

Get all Children of an Object with a certain component 0 Answers

SOLVED : How to scan and delete elements from a name/score array on a dreamlo database 2 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