NullReferenceError causing blocks to no longer be destroyed

I am working on the Block Breaker in the Unity 2D course and I am getting a NullReferenceError whenever the ball makes contact with a brick. As a result the bricks are not disappearing and my score will not update. Can somebody point me in the right direction? The last time had one of these errors I did not assign a value to a SerializedField, but I think there is something else wrong this time.

NullReferenceException: Object reference not set to an instance of an object
Block.DestroyBlock () (at Assets/Scripts/Block.cs:25)
Block.OnCollisionEnter2D (UnityEngine.Collision2D collision) (at Assets/Scripts/Block.cs:20)

Do you have a gameobject exposed in the inspector but not set. Typical cause. Not only obviously.

This mysteriously started happening to me too, I think related to the way I was using prefabs to hold stuff in scenes wasn’t meshing with the persistence of Game Session. If I remember right, I fixed it by having the Blocks script cache a reference to Game Session in Start().

Unless it was already doing that, then I have no idea.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.