- Home /
List Works But Still Get Argument Out of Range Exception
I'm getting this problem even though it's working as intended and would really like to fix this problem.
void Update ()
{
if (barbaricInput.ComboStore.Count > 0) {
if (!canComboAttack) {
if (barbaricInput.ComboStore [0] == ButtonPress.RIGHT && barbaricInput.ComboStore [1] == ButtonPress.RIGHT) {
Debug.Log ("Combo Attack");
canComboAttack = true;
}
}
} else {
canComboAttack = false;
}
}
ArgumentOutOfRangeException: Argument is out of range.
Parameter name: index
System.Collections.Generic.List`1[ButtonPress].get_Item (Int32 index) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/List.cs:633)
TheBarbaricCombo.Update () (at Assets/TheBarbaricCombo.cs:25)
Are you sure this is the bit of code where the error is happening?
Yea, it happens when i go to theComboStore at element [0] to check if the enum is buttonPress.Right. When that happens, the error will occur but the Debug.Log will still happen.
This is the sliced bit of code at the lower part of my overall code. So I guess it might've confused you when I put in the error log here.
Oh, ok. I know I've had a problem like this but I've forgotten the fix....I don't think I'll be able to help you ^^;
Answer by Kishotta · Jul 07, 2017 at 05:33 PM
The exception is likely being thrown in the second half of the third nested if statement. You check that there is at least 1 element in the list initially, but you access the 0th and 1st elements. You should have your first if statement check
if (barbaricInput.ComboStore.Count > 1) {
...
}
That's the only potential bug I see here.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
What's the proper way to see if a Vector3 List index is null? 1 Answer
generic list, swapping equipment errors but not always? 1 Answer
Error: Argument is out of range Parameter name: index 1 Answer
ArgumentOutOfRangeException: Argument is out of range in Generic.List 2 Answers