How the bug showed for me

So the solutoin in this lecture solved the bug for me. However I thought it could be usefull for others if I explained how the bug actually showed up for me.

Everything seemd to work for me, however after finishing a level and starting on the next level the score stopped increasing. Oddly enough, when finishing the last level and starting a new game, in the first level the score continued where it was last time I finished that first level.

I then included a number of debug logs to print the total score to the console. This showed that for each level the score was reset and started counting again from zero, except for the first level.

I had exactly the same behavior as yours.

Hi Tauq and welcome to our community.

I’m glad you figured it out on your own.

Great idea to add debug logs to see what is actually happening in your game.

I totally agree! I thought it was odd that the Bugfix video didn’t mention HOW the bug presented itself.
For me it was exactly like for you… no updating score.
:+1:

To elaborate on this: The blocks have a line of code, gameStatus = FindObjectOfTypeGameStatus(); that they use to find the GameStatus object that updates the score. At the very start of the second level/scene, the new blocks for that level are finding the GameStatus object that is getting deleted through the singleton pattern, when they should be finding the one that we are keeping with the DontDestroyOnLoad(); method. I believe Rick said in one of the lectures that FindObjectOfType<>(); will find the first object in the hierarchy, which for a split second is the GameStatus object that we are deleting with the singleton pattern.

If any other object is trying the find the GameStatus in the first frame they also might grab the one that we are trying to delete at the start of the new level.

Hope this helps!

1 Like

Privacy & Terms