What is NullReferenceException and how do i fix it?

i’m new to unity and got a problem where i want the blockcollider to block the player movement, it says it isn’t a code problem but when i start the game it shows me this:

if you can tell me what can i do with basic terminology i’ll greatly appreciate it

Hello! This is a standard answer for Nullreference questions.

It’s good to come to ask at UA, but before coming, you should try to solve your problem by your own. Just by typing your question at google will find the answer… In addition, you must know that in every error message, it says the line of code where is happening (ex: Cs 40,23).

A NullReferenceException happens when you try to access a reference variable that isn’t referencing any object. If a reference variable isn’t referencing an object, then it’ll be treated as null. The run-time will tell you that you are trying to access an object, when the variable is null by issuing a NullReferenceException.


First, check your error code, it says the line where the problem is .

Second, You need to debug the code while running, and check the states of the variables of the line at the moment the error occurs,

I’m sure you will detect what variable value is still NULL. Then investigate why.

Look for some tutorials on how to debug code while running on your scripting software if don’t know what I’m talking about.

Bye & good Luck!