Null Reference Exception in the List course from the Quiz Master Game

Hello :slight_smile:

I’ve just finished the part with the Lists and as soon as I remove the “GetNextQuestion(),” from the Start method, the game breaks.

I have a null exception that gives :

NullReferenceException: Object reference not set to an instance of an object
Quizz.DisplayAnswer (System.Int32 index) (at Assets/Scripts/Quizz.cs:63)
Quizz.Update () (at Assets/Scripts/Quizz.cs:47)

line 63 being if (index == currentQuestion.GetCorrectAnswerIndex())

and 47 DisplayAnswer(-1);

The thing is, after trying some stuff here and there, I took the course file from GitLab here Assets/Scripts/Quiz.cs · 00eda531443453dbbbfb92173899b3d75b350f67 · GameDev.tv / Complete Unity 2D 2021 / Quiz Master · GitLab to compare, and as I couldn’t find any difference, i decided to comment out my own code and copy/paste the content of this one instead. The problem remains with the teacher’s code. Is there something broken with the new version of Unity or something that I just totally missed ?

Thank you :slight_smile:

1 Like

Ok so I don’t know if it’s the proper way to do it but I managed to fix the problem by adding
currentQuestion = ScriptableObject.CreateInstance<QuestionSO>();
In the Start() method.
Hope that it will help someone, or that I’ll get a better solution :slight_smile:

3 Likes

i am now also getting this but the solution you said you found doesn’t work for me sadly

Ok for an unknown reason the forum removes a part of my code when I paste it, I didn’t notice when first sending. Here is the proper line :slight_smile:

1 Like

Hi @Alerazius,

Welcome to our community, and thanks for sharing your solution. :slight_smile:

I’ve just edited your previous answer, marked the concerning line and pressed the </> button to make the forum format the text as code. Without it, some parts do not become visible.


See also:

2 Likes

Thank you :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms