One thing I've gotten into the habit of doing is only loading scenes additively in Unity. I have one main scene that I call Main, and it never leaves. In this scene I place all global services. I then only change the scenes by adding or removing new scenes. To make this easy, I have developed the ScenesManager.
How the ScenesManager works
With the ScenesManager you can load new scenes:
All scenes are loaded additively. This means that the current scene is not unloaded. If you want to unload the scene, you have to do it manually:
You can also exit scenes based on certain conditions. To exit all scenes that start with a certain name, use:
To exit all scenes except a specific scene, use:
To exit all scenes, use:
There is also a helper method that exits all scenes and loads a new scene:
All loading and unloading operations are performed asynchronously.
Please note: If you want to use the ScenesManager, you can only use the ScenesManager. Do not use Unity's SceneManagement directly. This would lead to unexpected behavior.
Your Feedback is important!
What do you think of the services presented here? Is there anything missing or does something not work as expected? As always, I'm happy to listen to your feedback. Let me know what you think about this module. You can use the comment section below the article for this. You can also find other ways to contact me here. If you found a bug or want an enhancement, please create an issue in the GitHub repository. Further documentation can be found in the README of the corresponding module.
There are no comments yet.