The answer is always the same… ALWAYS. It is the single most common error ever. Don’t waste your life on this problem. Instead, learn how to fix it fast… it’s EASY!!
Some notes on how to fix a NullReferenceException error in Unity3D
Expect to see this error a LOT. It’s easily the most common thing to do when working. Learn how to fix it rapidly. It’s easy. See the above link for more tips.
This is the kind of mindset and thinking process you need to bring to this problem:
Identify why it is null
This is why I posted this thread, if I knew, there is no problem, problem is, human programmer don’t know why this happen because there is no reason in code, at least programmer knows.
Real problem is, same code, but at different computer’s unity project (slightly different at code, scene), only at one computer it (nullreference) happens.
So conclusion is, this is Unity’s problem and some malfunction at metadata or complicated scene, .sln file or something unity related.
Right, for example creating a MonoBehaviour or ScriptableObject derived class with the new keyword or something along the lines ^^.
Another question you should ask and investigate is the opposite question. Once you know what is null, you should ask your self / your logic why you think it should not be null. Since it is null the issues is most likely in your own reasoning.
export just 3 scripts total and importing it just has no problem, but just make 3 new scripts and copy and paste code result in null reference error. So then who’s problem? me? or unity or you?
If an export of a working project and importing it on the broken one fixes the issue, you most likely have renamed one of your files outside Unity so that the meta file link was broken. When you reimport the old file with it’s associated meta file you get back the original link that you specifically have broken.
Always search for the error on your side first, because in 99.9% of all cases that’s where the error is located. Unity is used by several 100k of peoples around the world. I’m not sure why so many people who probably just started working with Unity assume that they are the only one who found a huge bug in Unity that nobody in history has found. I work with the Unity engine for over 10 years now and I didn’t get a single null reference exception that wasn’t my fault.
You may be not aware of the meta data linkage and that every script has an asset ID which is used to link a serialized instance of one of your classes to the actual script file. If you delete or somehow loose the meta data file, Unity sees the script as a new asset and the script gets a new asset ID. This will break all already serialized instances of that script. This is true for components as well as serialized ScriptableObjects.