NullReferenceException error reason completely unknown, error occurs in Build only

I’m working on an endless runner game and everything is working well in editor - the character starts running as usual. But when I build the game on android I get a Null Reference error for no reason. What I mean by that is, when I tried an on screen debugger on the phone and also android logcat, these two lines are the only things I see, repeatedly-

NullReferenceException: Object reference not set to an instance of an object

Filename: currently not available on il2cpp Line: -1

These two lines keep on repeating throughout the log console on device while the player does not move and everything is completely messed up (sprites, positions), while the game locks up at 1 FPS.

Now this would usually be an easy fix. Usually NullReference exceptions come with reasons behind them in logcats. But in this particular case, neither the file name nor the exact error line of a script is specified. All I see are those two lines. No names. Nothing extra. To top it all, the game runs perfectly fine in editor.

Ironically, the only changes I made from the last working version was remove FindGameObjectWithTag and replace it with actual gameobject references within editor to speed things up. Every object in the editor is referred correctly.

My project is completely stuck because of this. Is there any way to atleast get a script name or something? No form of logging is helping here at all.

Solved. I re-imported the entire projected. It was all probably caused by the deletion of tags requiring a reimport. Or it could have been the cache being problematic previously.

1 Like