NullReference errors disappear when trying to debug them

The problem is that a variable (initialized in code, not inspector) suddenly becomes NULL during runtime.
It happened twice today. But the thing is, when I try to use VS debugger or DebugLog “missing” object’s name, everything works just fine. Even more so, the first error got resolved by adding and removing Debug.Log. However the second error keeps coming back after a few restarts.
I’ve never encountered such error, what can possibly cause it?

If the NRE is in the editor (look at the callstack in the error!)), Reimport-All or Reset-Layouts may help you.

If the NRE is in your code, make sure you’re accounting for non-guaranteed order of execution.

Here is some timing diagram help:

Here is an abbreviated and better-annotated version of the above:

1 Like