NullReferenceException: Object reference not set to an instance of an object

i was getting this error and i check everything twice and found a way to fix this either you comment DisplayAnswer(-1); this line of code or add currentQuestion = ScriptableObject.CreateInstance(); this line in start it works for me and i hope it will work for you as well
NullReferenceException: Object reference not set to an instance of an object Quiz.DisplayAnswer (System.Int32 Index) (at Assets/Scripts/Quiz.cs:60)
Quiz.Update () (at Assets/Scripts/Quiz.cs:44)

1 Like

Had the same issue too. It seams there is a race condition between the timer script and the quiz script. The Quiz update is being called before the Timer Updates first iteration.

I fixed it by doing

 else if(!hasAnsweredEarly && !timer.isAnsweringQuestion && currentQuestion != null)

in the Quiz Update method

2 Likes

I had the same issue here and solved with your comment I cleared my mind and solved this problem in code, thank you very much for your help.

1 Like

ty for pointing me in the right direction. with me even with extra && it was giving me a bug that flashed the default screen at start of game, so I added.
void Awake()

{

    updateTimer();    

}

to Timer script this worked to resolve bug by making sure that timer won the race of who is on first. but still use extra check to be on safe side

Privacy & Terms