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 /
  • Help Room /
avatar image
0
Question by gbunny101 · May 27, 2016 at 05:47 PM · error messageargumentexception

ArgumentOutOfRangeException Error in my game

I am trying to build a quiz game. I got two scripts, a Question Data and a Question Manager script. In my QuestionManager script i keep getting this error when i try to set a new question. I've tried to resolve it but i can't seem to get it fixed. Error ArgumentOutOfRangeException: Argument is out of range. Parameter name: index System.Collections.Generic.List`1[Question].get_Item (Int32 index) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Collections.Generic/EqualityComparer.cs:84) QuestionManager.SetNewQuestion () (at Assets/QuestionManager.cs:30) QuestionManager.Start () (at Assets/QuestionManager.cs:21)

this is my QuestionManager script

 public class xxxxxxx {
 
     [SerializeField]
     private TextAsset questionDataXMLFile;
     public QuestionData questionData;
     private Question currentQuestion;
 
     [SerializeField]
     private Text factText;
     
     void Start() {
         questionData = QuestionData.LoadFromText(questionDataXMLFile.text);
         factText = GetComponent <Text>();
         SetNewQuestion ();
 
     }
 public void SetNewQuestion() 
 {
         int index = Random.Range(0, questionData.questions.Count - 1);
 
         Debug.Log (index);
 
         currentQuestion = questionData.questions[index]; 
 
         factText.text = currentQuestion.questionText
     }
     
     // Use this to see if user selected correct answer
     public bool CorrectAnswerSelected(int selectedAnswerID) {
         return selectedAnswerID == currentQuestion.correctAnswerID;
     }
 }

Comment
Add comment · Show 1
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
avatar image Jessespike · May 27, 2016 at 06:04 PM 0
Share

format you code please, use the 101010 button.

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Jessespike · May 27, 2016 at 06:10 PM

Are the questions even loading? How many are being loaded? You didn't share how QuestionData is structured, so it's hard to say if anything is wrong there.

  Debug.Log( questionData.questions.Count );

Don't think you should be subtracting 1 here:

 int index = Random.Range(0, questionData.questions.Count - 1);

it should probably be:

  int index = Random.Range(0, questionData.questions.Count);
Comment
Add comment · Show 1 · Share
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
avatar image gbunny101 · May 27, 2016 at 07:21 PM 0
Share

Yes i made a mistake in the X$$anonymous$$L file and the questions were not being loaded..thanks for answering my question!

avatar image
0

Answer by Tasarran · May 27, 2016 at 06:06 PM

You are referring to questionData.questions[], when you never define questionData as containing a questions[] array.

Comment
Add comment · Share
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

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

57 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

Related Questions

ArgumentNullException When using Collider2D.OverlapCollider() 1 Answer

OpenCVForUnity 0 Answers

JsonUtility.FromJson<> has ArguementExceptions 0 Answers

Error CS1729 the type UnityEngine.Vector3 does not contain a constructor that takes 4 arguments and 1 more... 1 Answer

64,24): warning CS0219: The variable `nextTetromino' is assigned but its value is never used, (131,163): error CS0119: Expression denotes a `type', where a `variable', `value' or `method group' was expected 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