Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

how to locate ArgumentOutOfRangeException: error?

Discussion in 'Scripting' started by ozgurdugmeci, Oct 2, 2015.

  1. ozgurdugmeci

    ozgurdugmeci

    Joined:
    Mar 1, 2015
    Posts:
    85
    On editor log file I discovered that unity has an error below :

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

    It doesnt point to a specific script and line. How can i find which script is causing the error?
     
  2. Sykoo

    Sykoo

    Joined:
    Jul 25, 2014
    Posts:
    1,394
    It's usually caused by arrays when they are not registered as new.

    Make sure to have your arrays setup like this:
    Code (CSharp):
    1. public int[] myArray = new int[1000];
    2. public GameObject[] myArrayObject = new GameObject[1000]
    3.  
    4. //The 1000 number inside of [] is for amount of spots there are in the array.
     
  3. ozgurdugmeci

    ozgurdugmeci

    Joined:
    Mar 1, 2015
    Posts:
    85
    I changed all
    Code (JavaScript):
    1. var GObj: GameObject[];
    as :
    Code (JavaScript):
    1. var GObj = new GObj[100];
    When I press play unity editor shows no error but I am still getting the same error on editor log.
     
  4. Sykoo

    Sykoo

    Joined:
    Jul 25, 2014
    Posts:
    1,394
    In Javascript it should look like this:
    Code (CSharp):
    1. var myObject : GameObject[] = new GameObject[100];
    2.  
    3. void Start() {
    4. }
     
  5. ozgurdugmeci

    ozgurdugmeci

    Joined:
    Mar 1, 2015
    Posts:
    85
    sykoo the error still remains on editor log.
     
  6. Sykoo

    Sykoo

    Joined:
    Jul 25, 2014
    Posts:
    1,394
    Hmm... are you sure you did this with ALL the arrays you're using?
    Bu arada, memnun oldum Özgür! :)
     
  7. ozgurdugmeci

    ozgurdugmeci

    Joined:
    Mar 1, 2015
    Posts:
    85
    there was just one left.
    it was different than the others.
    I changed it as well.

    And it worked mate. thanks heaps.

    eyvallah :)
     
    Sykoo likes this.