- Home /
ArgumentOutOfRangeException is occurring but I don't know why. (SOLVED)
EDIT: This was a dumb question and I made a dumb mistake. But I'll leave the post here so people can mock it/learn from it/get angry. Maybe my next question will be better. Thanks all!
Hi, this may be a dumb question, but I need to ask since I'm a novice and a little stuck.
I am working on a project in which the user is given a card at random, based on the range of cards that are available in 'Playables' in the Resources section. Most of this code works (if you have any notes on it, I'd love to hear them though).
The problem comes when I get to 'CharacterAsset chosen = filterList[selection];' Because then this error comes up:
So what I understand to be happening is that the playables are being pulled from resources, because the characterList has a 28 length. The selection is selecting a number that is correct in the range - 6 in this case. But then when a try to attach the asset to chosen, it springs the OutOfRangeException. And I don't know why that would be. And any help would be gratefully appreciated. Thank you in advance. Oh also, the code is below in full, along with some noted out code in an attempt to track the problem, and the debug logs I used for the same reason.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CharacterSort : MonoBehaviour
{
public static CharacterAsset[] characterList;
public static List <CharacterAsset> filterList = new List<CharacterAsset>();
int selection;
// Start is called before the first frame update
void Awake()
{
}
void Start()
{
characterList = Resources.LoadAll<CharacterAsset>("Playables");
Debug.Log(characterList.Length);
selection = Random.Range(0, characterList.Length - 1); //filterList.Count - 1);
}
// Update is called once per frame
void Update()
{
}
public void PluckCharacter(/*int category_A, int category_B*/)
{
//foreach (CharacterAsset character in characterList)
//{
// filterList.Add(character);
//}
Debug.Log(selection);
CharacterAsset chosen = filterList[selection];
Debug.Log(chosen);
}
}
Your answer
Follow this Question
Related Questions
Argument out of Range 1 Answer
ArgumentOutOfRangeException: Argument is out of range in Generic.List 2 Answers
ArgumentOutOfRange error with list 1 Answer
For loop not repeating - (JAVASCRIPT) 1 Answer
List Emptying Itself? 1 Answer