Singleton Pattern Problems

Hi there, I’m new to the community, and this is the first issue I’ve come across doing the 2D Unity course. So here’s the issue :

When I press play on my block breaker game, the Game Status is deleted from the level hierarchy, making the ball speed settings go back to normal and the score text disappear (even on the first level). On top of that, the block doesn’t break anymore, on either of the levels. Here’s a few screen shots of my scripts and the console errors, along with the hierarchy, if that helps. If you need any more info or screenshots, I’ll be happy to oblige! Please help, I just want to continue the course :frowning:

So, if you check the errors, your game status is having a nullpointer exception in the game status script,more specifically in the start method.

So, it’s not finding the scoreText Object.

My guess is, that you linked the score text to the GameStatus by dropping it into it, via the inspector (since it’s a serialized field) in your code.

My guess is that something about the singleton breaks that, although I wouldn’t know what. Make sure you still have it linked in the inspector, and if it’s still linked in the inspector, try if you can find it in runtime, instead of having it as a serialized field.

Thanks for your reply !

I looked closer at the scoreText Object, and it turns out there was a problem with the prefabs not being the same in each scene. So I deleted the the existing Game Status along with the child game Canvas and Score text from the hierarchy and added the Game Status prefab and Game Canvas separately, remade the Score Text, and then parented them to the Game Status Object. Finally, I made sure to apply the changes only on the Game Status. That seemed to work pretty well. It’s silly how simple the problem was!

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

Privacy & Terms