NullReferenceException weird error

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?

Provide more information around IsTaken and how you created the array but from what I can guess, it’s likely that Slot is returning null.
Setting the size of an array does not initialize it with a value, it only register X amount of space for it in memory. Confirm that Slot is not null and that you are initializing it with a value correctly before calling this line:
Slot*.IsTaken = false;*