Can't get it to carry over between scenes

Hello! I am using this technique in another game of mine (Exact same code) to carry over and count “Kills” between scenes. But whenever I transition between scenes the score counter resets, and then it also stops counting kills.

Any idea what could be wrong? I’ve used the exact same game objects and scripts, with the same names to avoid controversy. I then added the FindObjectOfType<GameSession>().AddToScore(scoreValue); code to my Die method on my enemy script. It works fine for one scene, then it just… turns off and the number in the corner turns to a zero.

Thanks in advance! Loving these tutorials :slight_smile:

Hi Josef,

I would imagine that your GameSession object is being destroyed, or, when the second scene loads it has access to another instance of the GameSession object which doesn’t have your score associated with it.

There was a fix put in for the singleton code at the end of Block Breaker - might be worth taking a look in case you’ve missed this.

Hope this helps :slight_smile:

That was it! I had other GameSession objects prefabbed and dragged into the other scenes. Thank you!

1 Like

You’re very welcome Josef :slight_smile:

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

Privacy & Terms