The following error message appears whenever I open my project. It doesn’t prevent me from running the project or playtesting the game, but every time I press play this error is generated once again (excluding the last line). Has anyone seen an issue like this before?
The error doesn’t prevent me from running the project, but each time I do so the error generates again (except for the last line, which only generates upon opening the project). This will eventually cause unity to crash. It isn’t consistent how long this takes but usually after 3 or 4 runs Unity will crash.
This issue cropped up after I added some functionality to the OnEnable() function in my player script, but removing that part of the script and removing the player object entirely were not able to solve the problem. I even created an empty scene in the project with nothing but the default light and camera and this issue persists.
If there’s anything else that would be helpful to know, don’t hesitate to reply and ask for more. Thank you.
Error message shown below.
NullReferenceException: Object reference not set to an instance of an object
UnityEngine.JsonUtility.FromJson[T] (System.String json) (at :0)
UnityEditor.StateCache`1[T].GetState (UnityEngine.Hash128 key, T defaultValue) (at <46e1bf9196684231bfdf718689da7102>:0)
UnityEditor.Tools.OnEnable () (at <46e1bf9196684231bfdf718689da7102>:0)
UnityEditor.EditorAssemblies:ProcessInitializeOnLoadAttributes(Type)
What Unity version is used ?
And what is your full script code ?
Looks like a Unity bug, did you try delete the Library folder and reset the Unity windows layout ?
The Unity version is 2022.2.19f1
The full script code is pretty long, over a thousand lines, and even when I remove the object that has it the error still shows up at the same times. Here is the whole script regardless.
I tried deleting the the library folder and resetting windows layout Unity windows layout, which had no effect.
PlayerMove.cs (39.7 KB)
The error appears to be coming from the engine, though you are on a rather old version of Unity. It would be worthwhile doing an upgrade to the latest 2022.3 LTS (following proper version control practices should things go awry).
I updated Unity and tried running the project again. The error persists but is SLIGHTLY different.
NullReferenceException: Object reference not set to an instance of an object
UnityEngine.JsonUtility.FromJson[T] (System.String json) (at <97cb9d38073941518be7ea7279a10e80>:0)
UnityEditor.StateCache`1[T].GetState (UnityEngine.Hash128 key, T defaultValue) (at <8d33a6384e1148858f2e669234fa89ff>:0)
UnityEditor.Tools.OnEnable () (at <8d33a6384e1148858f2e669234fa89ff>:0)
UnityEditor.EditorAssemblies:ProcessInitializeOnLoadAttributes(Type)
The long strings of characters, which had always been the same before, are now something different.
I will try that, thank you. Do you have any thoughts as to what might have caused these errors to start cropping up?
Also My understanding of a “library clear” is just to delete the library folder and then open the project again to let it regenerate. Is there something else beyond that I should be doing?
I mean it’s hard to say where exactly the null-ref is coming from, though it’s something on the engine’s side and unlikely to be anything to do with your own code.
Potentially there was a bug in the older version writing some faulty data. Hopefully this is fixed in the current versions, and the data just needs to be regenerated to let it write the correct cache.
This is just a guess of course.
To which Unity version did you upgrade ?
Generally any x.1 or x.2 versions should never be used for production as can create massive issues later.
The x.3 and LTS are the safest bets to use always from my experience
Also check