- Home /
Argument out of range
I have a function that has the following code:
int random = Random.Range( 0, playerCards.Count - 1 );
return playerCards[ random ];
The function throws an "Argument out of range exception", right before i call the function i populate the playerCards List like so:
for( int i = 0; i < 25; ++i )
{
playerCards.Add( i );
}
Can't seem to find what's wrong, please help me and thank's in advance.
Well but im only calling the function after the loop, so the list must be full right?
Right before you get the error, output the size of the array. Edit your question to include more of the code or even the whole script. There are a variety of possible problems, but we need to see the script.
Oh thank's a lot i managed to solve it. Another script must be changing this variable because when i delayed this script it worked fine. Now I just have to check wich one is changing the value and why.
Your answer
![](https://koobas.hobune.stream/wayback/20220613161355im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
generic list, swapping equipment errors but not always? 1 Answer
A node in a childnode? 1 Answer
Clear Does not work to remove 1 Answer