Timer works, but button disappears


Greetings, been working on this 3rd project/Quizmaster for a time now, but having some issues.

After following the lessons and code so far, I ran into this issue here: the timer/fill fraction stuff works fine, but now the last button disappears?

I even ended up using the code from the Project Changes just to double-check, and still the same issue.

1 Like

Hi,

The last button seems to be in the Hierarchy. This means that it is there. Maybe the box in which the buttons get displayed is too small. Try to make it larger.


See also:

Greetings, I was able to move the button, but now upon more playtesting, it’s something up with the QuestionSO script code.

I’ve followed each and every step, but now, no matter what answer is put in the correct answer Index, on playing it, the button gets deleted and can’t be clicked.


So I ended up looking at the Quiz script, specifically the DisplayAnswer (int index) portion, and changing one thing in the else statement:

buttonImage.sprite = correctAnswerSprite

into buttonImage.sprite= defaultAnswerSprite

is this a glitch with the code or maybe Unity reading correctAnswerSprite incorrectly somewhere?

is this a glitch with the code or maybe Unity reading correctAnswerSprite incorrectly somewhere?

That’s a good question. Have you already tried to add Debug.Logs to your code to see what is going on during runtime? Maybe Unity assigns the “wrong” sprite.

And have you already compared your code to the Lecture Project Changes which can be found in the Resources of this lecture?

I added the Debug.Log to the method of DisplayAnswer else statement, and now changed defaultAnswerImage back to correctAnswerSprite and it’s working fine now.

Does that mean you fixed the issue? Or is there still a problem you’d like to solve?

NullReferenceException means that a reference (“link”) to an instance is missing. Double click on the error message to see to which line in your code it is referring. If you exposed a field in the Inspector, make sure that it’s not empty.

For the NullReferenceException, it’s just pointing to DisplayAnswer(-1) and the if (index == currentQuestion.GetCorrectAnswerIndex()) parts of the code, but no error there from what I see.

And so far as I’ve seen now in playtesting, original issue is fixed now.

Check if and where an object gets assigned to currentQuestion. The value must not be null. Use Debug.Log to see the value during runtime.

Greetings again, after completing the GameManager video, and setting Start methods to Awake, everything is working great now. Thank you again

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

Privacy & Terms