1
\$\begingroup\$

I am having a bit of a headache right now about my controllers: Ive got a bunch of managers in my game, for example A MasterController to manage most serious stuff like pausing or turning off input AudioController, CutsceneController, PauseMenuController and so on.. Also my game has about 30 levels = about 30 different scenes. Every one of these scenes needs that bunch of managers to work properly. At first I tried to make them all children of a same GameObject and then make this gameobject DontDestroyOnLoad and simply put it on the very first scene, which is Main Menu. In that case they will just travel around scenes along with a player and everything is working fine. The thing is that I want to test some stuff in, lets say, scene 23 and when I open scene 23 there are ofc no managers there so I need to put them all in this scene to test anything out. So whats the point of DontDestroyOnLoad if, for testing and debugging I still need to put all those managers in every single scene? I just cant figure out the good way of doing this manager stuff, help pls!

\$\endgroup\$
2
  • \$\begingroup\$ They are in every scene but usually as a singleton with some logic that they are n ot duplicated in a scene but can hold data between scenes. You could alternatively as well make a loader scene and from there load your actual scene. \$\endgroup\$
    – Zibelas
    Commented Jul 2 at 17:57
  • \$\begingroup\$ Does this answer your question? How to load DontDestroyOnLoad object from menu scene when testing other scenes? \$\endgroup\$
    – DMGregory
    Commented Jul 2 at 21:22

1 Answer 1

1
\$\begingroup\$

I often solve this by creating a single "Every Level Stuff" prefab where I put all those global controllers and managers and then put an instance of that prefab in every level. When your game has a lot of levels, then it can make sense to create a Scene Template that already has that prefab instance, so you don't need to add it manually every time you create a new level.

You just need to make sure you apply any changes you make to that prefab, so you don't end up with slightly different versions of it in different levels. Although sometimes that might be intended. For example, if you want some components on that prefabs to have different values depending on the level. Then any global changes to the prefab should be done by editing the prefab itself in prefab mode.

\$\endgroup\$
2
  • \$\begingroup\$ I totally agree with this, but I think it fails to answer the core question of OP: So whats the point of DontDestroyOnLoad if, for testing and debugging I still need to put all those managers in every single scene? \$\endgroup\$
    – Zibelas
    Commented Jul 3 at 5:29
  • \$\begingroup\$ @Zibelas The way I read this question, it's asking about the "Correct way to manage managers and controllers in Unity". The question about the point of DontDestroyOnLoad seemed rhetorical to me. But if you would like to explain that in detail, feel free to write an own answer. \$\endgroup\$
    – Philipp
    Commented Jul 3 at 9:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .