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 /
avatar image
0
Question by Crash370 · Dec 01, 2019 at 10:57 AM · argumentoutofrangeexception

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:


alt text


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);
 
     }
 }


range-problem-2.png (25.8 kB)
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

0 Replies

· Add your reply
  • Sort: 

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

114 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


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