I have 2 scenes, a menu scene and a game scene. All managers are created in the menu scene, and they all DontDestroyOnLoad. My problem is that to test the game in play mode, I need to run play mode from the menu scene every time, since there are no managers on the game scene initially. Is there any way I can access the managers without running the menu scene?
This is the pattern I use:
Some super-simple Singleton examples to take and modify:
Simple Unity3D Singleton (no predefined data):
Unity3D Singleton with a Prefab (or a ScriptableObject) used for predefined data:
These are pure-code solutions, DO NOT put anything into any scene, just access it via .Instance
Alternately you could start one up with a [RuntimeInitializeOnLoad] attribute.
There is never a reason to place a GameObject into a scene if it will be DontDestroyOnLoad.
If you do, then sometime in the future you (or a teammate) will very likely:
- drag it into something else that isn’t DDOL. FAIL
- drag something else into it that isn’t DDOL. FAIL
Just DO NOT PLACE anything into a scene that will be marked DontDestroyOnLoad.
Just Don’t Do It!![]()
I came here because I knew someone was going to suggest Singletons ![]()
But before we start the age old argument singletons or not singletons
I just want to tell OP that they should abstract their way of thinking and not box themselves into scenes. A menu scene should still be in a game scene there’s no real reason you should be separating the two and it will just be more complex in the long run.
menuCanvas.SetActive(false)