Null reference without location

Hey everyone!

I am getting a null reference during runtime, but it doesn’t show the location other than highlighting the GameObject the script is placed on.
However, I got a bunch of scripts on that object and the scripts themselves are rather large ones as well.
How would you debug something like this?
Of course, I could step by step go through the scripts and try to deactivate stuff and see if the error goes away, but is there no alternative for getting the file, line and character number data?

Best wishes,
Shu

Null References are a very common problem and are most often easily fixed.

Can you share the code and the line that triggers this exception ?
Also, if you use Visual Studio, you could use Attach to Unity to check on your local variables at each step of the code. You could then see what goes null and why.

1 Like

Thanks for the reply, @LaGrangeEURL !
Unfortunately, I can’t share the code, since I’d have to share all of it (a few thousand lines), which may be affected, because I don’t know the line of it. That’s the issue: I don’t know the location. I have probably fixed a few hundreds, if not thousands, of those, but I normally get the following infos: Within which script file does it occur? Within which line? Which character number of that line? But that info is completely missing. It just states there’s a Nullreference and that’s it.
I’m not sure I can attach VS Code to Unity (I’m still using a very old version (even <1.0 I guess). But I may have a look next time I’m working on this!

Does it have a stack trace?

1 Like

Please share a screenshot of the Console output, the location should be displayed there

1 Like

I can get visual studio to break on null reference exceptions. Bring up the exception settings and select it to break on specific exceptions. There’s a long list of exceptions, you can use the search in the exception settings window to search for nullref to find the option. I had to uncheck it and check it again before it started working…

I haven’t really debugged in VSCode, but perhaps they have similar options

1 Like

Not in VSCode or Visual Studio, I’m talking about the Console window in Unity. It will pinpoint the NRE

1 Like

@kdgalla
@Hikiko66
Thanks for the suggestions! Both sound like great plans! Haven’t had a look at either so far, since I’m currently working on something different, but I may give it a try later! Unless JeffDUnity3D knows a solution right away, of course.

@JeffDUnity3D
Thanks for the replies! That’s what the Console looks like (no other issues, the only error showing up):

Fixed it. Was a missing RectTransform, I think, on an object within a list. Seems like a bug its location wasn’t reported in the Console.