Xerios / ScreenManager

Flexible way to manage screens with transitions for Unity
MIT License
560 stars 69 forks source link

Going back to ScreenManager scene #5

Closed ryanslikesocool closed 7 years ago

ryanslikesocool commented 7 years ago

I absolutely love this UI solution, but when I go to a different scene and come back to the one with the ScreenManager, the UI doesn't show up. When I look in the inspector, all of my UI elements are inactive and in the inspector, the game object with the ScreenManager looks like it's missing a few things. Am I doing something really dumb because ScreenManager is not supposed to be used this way?

Xerios commented 7 years ago

Thanks :)

I don't think I made ScreenManager to be persistent across scenes, so for your issue there are two possible solutions: Either add DontDestroyOnLoad(transform.gameObject); to your ScreenManager object or simply put the screen manager in a shared scene ( with Unity's new multi-scene workflow, this shouldn't be an issue ).

Tell me if any of these solutions fixes your issue, thanks 👍

ryanslikesocool commented 7 years ago

The DontDestroyOnLoad didn't work because I didn't have a top level object. I had trouble figuring out the shared scene. What solved my problem was unregistering the ScreenManager before I loaded the scene and letting it do it's thing from there. The ServiceLocator didn't allow me to re-register the ScreenManager, which was my problem.

Xerios commented 7 years ago

Normally ServiceLocator has an option to overwrite existing service using the second param Register<T>(T service, bool overwrite = false). If that works --even though it's a small change, a pull request would be much appreciated