ScenePersist.cs singleton not working

I copied Rick’s code and hooked things up as he suggested in the hierarchy (i.e. childing ‘enemies’ and ‘coins’ to the newly created ‘Scene Persist’ game object). However, the behaviour of my game is different to Rick’s.

In Rick’s game, it remembers how many coins he collected each time he dies, but - when he’s lost all his lives - it resets and all the coins reappear.

With my game, it remembers how many coins I collected each time I die, but - when all lives are lost - it doesn’t reset. So, if I collect 1 coin - that coin is gone forever for all subsequent playthroughs.

Not sure what I’m doing wrong as my code/hierarchy organisation looks identical to Rick’s…

Any support = gratefully received :slight_smile:

I would check the code in your GameSession, particularly the ResetGameSession function to ensure you are indeed calling FindObjectOfType().ResetScenePersist(); (this is what resets your ScenePersist when all lives are lost). Also make sure this is being called BEFORE GameSession destroys itself, otherwise the ScenePersist.ResetScenePersist() will not be called.

Does the same thing happen with enemies or upon completing levels?

Privacy & Terms