way to view what is returning null

is there a way to view what is causing my null reference exception.
when i click on it it tells me the script the error is from but not what is returning as null, this leaves me with no idea how to fix it as i dont even know where to start looking

The error message contains a filename and a line number for your error.

Typically there is only one or two possibilities for what could be null on the given line.

Some notes on how to fix a NullReferenceException error in Unity3D:

http://plbm.com/?p=221

Click the error, learn how to read errors and look up parts of code by line number.

The important parts of the error message are:

  • the description of the error itself (google this; you are NEVER the first one!)
    - the file it occurred in (critical!)
    - the line number and character position (the two numbers in parentheses)
  • also possibly useful is the stack trace (all the lines of text in the lower console window)

Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.

All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don’t have to stop your progress and fiddle around with the forum.

The full spiel:

How to fix a NullReferenceException error

https://forum.unity.com/threads/how-to-fix-a-nullreferenceexception-error.1230297/

Three steps to success:

  • Identify what is null
  • Identify why it is null
  • Fix that
1 Like

i am unsure what can be declared null, could playerTransform be declared null? (private Transform playerTransform)

Yes such a variable would be null by default unless you are assigning it to not be null somewhere.

Any reference type can be null. Value types cannot be null. It’s important to understand the difference in C#.

Examples of value types are ints, floats… vector3 is also a value type because it is defined as a struct, not a class.

Reference types are defined by classes. Things like GameObjects or any type of Component is a reference type and can be null. That also means that any MonoBehaviour script that you write is a reference type too.