Possible solution for NullReferenceException error

Atleas in my case, the error was caused by removing the [SerializeField] from the currentQuestion variable.
Removing the field in the inspector give to the variable a null value, thats causing the error when the game starts, because it’s value it is setting up after the GetRandomQuestion method is called, and thats is located in the update method.
So to fix it, i’ve just added back the [SerializeField] and reassigned back the Scriptable object in the inspector at the currentQuestion variable, hoping it will not mess up stuff later, but that’s will be probably a story for next time.
Hope i helped someone struggling with the same error.

3 Likes

You did, thank you.
Also, in my struggle I found out that you can add " currentQuestion = new QuestionsSO(); " at the Start() method of the Quiz script, which will assign a random value to the currentQuestion variable. This will get the program running but you are going to get a warning at the start.

Privacy & Terms