NullReferenceError - How i got it solved, it may help some

Hi there,

Just because i went crazy on this problem (for another reason than those posted here), I wanted to share in case another newbie had the same situation :

If you’re like me you, like to organize the Hierarchy and add plenty of objects into “folders” (which are technically empty gameObjects) to try some stuff.
In this case I named folder “Score” with other objetcs in it, including the actual Text “Score” we needed to use, resulting in the NullReferenceError.
The getComponent then loads the empty gameObject “Score” instead of your actual text “Score”…

Make sure the empty gameObjects are not named the same way as important objects !

Hope this will help if needed !



1 Like

Similar situation here. I had just, among some other minor changes, duplicated my Score object (in Unity) and renamed both objects into 2 versions:

  • GameTxt (Just a string that said: “Score:”, I had immediately removed script etc)
  • GameCalc ( the smart one that kept updating the score, that used the Scorekeeper script)
    Suddenly NulReferenceErrors all over the place.

Your suggestion helped me finding the solution fast (I was looking in all the wrong places)

Privacy & Terms