Null Refrence in quiz game at last

hi can you help me with null refrences , When i serialize or public the Quiz and End Screen Script it will work but when i make a refrence through “FindObjectType<>” it shows compilation error.

when i do this

this error are occur

but when i serialize and made reference in unity it works can you explain why it was happening

by the way my english is weak so please try to understand my question

You’re not showing all the code. These errors come from Start() and Update(). Please show us those

Hi Pentagon,

Welcome to our community! Enjoy the course and happy coding! :slight_smile:

NullReferenceException means that a reference (“link”) to an instance is missing. Maybe the FindObjectOfType methods were not able to find any Quiz and EndScreen object. In that case, the value of quiz and endScreen is null.

FindObjectOfType can only find active objects in the Hierarchy. If the objects are disabled, the method is not able to find them. If the objects need to be disabled, use [SerializeField], and assign the references manually, not with FindObjectOfType.

I hope this helped. :slight_smile:

See also:

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

Privacy & Terms