Re-instantiating Player Singleton with Events on Player Death

I had deviated from the course tutorial by using Events to update the UI. Then ran into a problem, the UI health was not updating when the Player Singleton was recreated when Scene was reloaded.

The question is, if Player singleton instance is recreated when scene is reloaded, do all of the classes subscribing to its events will also have to be re-instantiated ?

If DontDestroyOnLoad is used, the singleton isn’t recreated when the scene reloads because the singleton isn’t destroyed. But that doesn’t matter. Anything that is reloaded is, well, reloaded. That means all your events will have to be subscribed again because the objects that originally subscribed no longer exist. The code in your screenshot should be fine, though, because it subscribes in Start. This means when the scene reloads it will subscribe again.

THanks.

That fixed it. Had to turn the UIUpdate script into a singleton so when it was Destroyed, a new Instance was recreated.

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

Privacy & Terms