Singleton Pattern has ruined my ScoreKeeper apparently

My code for both ScoreKeeper and LevelManager are the exact same, word for word, as this person’s post: Error with Scorekeeper

I tried following the advice in a response there to change the Awake to Start in LevelManager, but that didn’t work either.

Basically, my GameOver screen can go back to the menu, but neither the GameOver nor the Menu screen will go back to the game because it reads a NullReferenceException on the method of LoadGame() and the GameOver.Start(), both of which use ScoreKeeper. I felt I did everything in the video, and I guess I’m not the first person to have this issue.

I looked at what the other student said they did, that adding a reference helps, but I’m not sure where exactly that should go and what it would look like.

Any help anyone can provide?

Have you tried the thingy-ma-jig and the whats-ya-calls-it? :wink:

In all seriousness, it’s tough to know without details. Often a NullReferenceException means something hasn’t been hooked up right, or some search for an object/component failed and the program continued without null checking.

So without knowing any more details, try making sure stuff is hooked up right (that also includes the scenes themselves).

Your editor will say, null reference exception and tell you which script and line the error occured. That’ll give you a good starting point to know where you should start to look.

Oh, I thought the tagging automatically connected it to the lecture I was responding to. This is for the Unity 2D games course, the final unit, Laser Defender. And the link I put in the post also included the exact code I used too.

Everything seems hooked up right, but I’ll try messing around with it too.

I did look at the line error and that’s what led it to the LoadGame and GameOver.Start methods I mentioned.

I get where you’d think that. It would be good if there were links to the reference material (there isn’t) but knowing the reference material won’t help anyone help you solve your issue. To get help around here, you gotta “help me help you” as they say. Post some code/approprate images.

So, I was having this issue too, but I solved it and I think I understand what was happening.

I was getting a NullReferenceException when I added scoreKeeper.ResetScore(); to my LoadGame() method in LevelManager. I wondered why it was not working when I clearly had a ScoreKeeper present, but then it hit me. I was working on the MainMenu scene, which I didn’t actually have a ScoreKeeper on, because why would you need the score on the main menu?

Since there was nothing to grab, I figured that’s why I was getting the error. I just put the ScoreKeeper prefab onto the MainMenu scene, and I haven’t had an issue yet. Although I’m sure I haven’t completely tested it to its limits, I think this might be what’s causing the issue. Hope this helps!