The game works just fine while in the editor and the Play button is pressed, but once built it just shoots out one error after the other.
It always gives a “NullReferenceException: Object Reference not set to an instance of an object”.
Now when looking into it, this shows up on lines of code where i am getting the components through code (the usual GameObject.Find("X").GetComponent<Y>();)
Then i tried making these variables accessible in the inspector and dragging and dropping the game objects directly onto fields. This get’s rid of the previous error, but now trying to access these variables later down the line pops up new errors.
Case in point:
I have a public int variable named Coins with an initial value of 0.
Then, another variable named CoinCounterText that contains the text box that displays the number of coins you hold. This is done using:
CoinCounterText.text = Coins.ToString()
Which ends up throwing another NullReferenceException.
I honestly don’t know where to begin solving this issue, it all works great until you build the thing.
Looks like cant find the “X” object, this of course may not be a full solution as you still need that “X” i assume
Sometimes the above may work if is an initialization issue, e.g. “X” is initialized after the code breaks so will never happen and be always missing, but if do the above check may be initialized and work right afterwards