I have a class array that I set its size from the “Awake” function and then use in different functions. The problem is that when I start unity and click on play or build my game to test it, I start getting this error:
"NullReferenceException: Object reference not set to an instance of an object"
Coming from this line:
Slot*.IsTaken = false;*
Which is the first line where I start using my array. I thought I had a problem with my array size so I debugged the array size in the “Update” function and I got the same size that I set in the “Awake” function. The weird thing is that when I click on the game object that holds this script, the errors are gone and it starts working fine. But this is not a solution since there’s no way it will work outside the unity editor with this error. Oh, and by the way, I’m using Javascript. Is this a common problem with arrays in unity? How can I fix it?