NullReferenceException Error, Please Help!

Hey Everyone,

I’m really at a loss with how to fix this issue. I’m trying to activate GUI elements based on collecting the objects in the scene. However, the following code seems to the main culprit creating this error:

The tutorial I’m following uses this code to deactivate the game elements, in order to activate them after collecting the right objects, displaying them on the screen in real time. Whenever I comment out this section of the code, the game works except for the canvas displays all the visual elements that I’m trying to activate.

Is there a better way to dynamically deactivate/activate GUI elements that avoid returning a nullreferenceexception error?

Adding the whole script in code blocks will help anyone that wants to help with you issue, as also writing the full error, as it will contain the line number.

In any case, from this code it seems that one or more of the item variables are null, probably because it cannot find the appropriate GameObject with the Find methods.

1 Like