- Home /
What's better? Managers using DontDestroyOnLoad or keep one in each scene?
When it comes to making your game use less memory, reducing overall load times and keeping framerate up, do you have your Managers (Camera, Input, etc) use DontDestroyOnLoad and follow the player throughout the game OR do you put them in a prefab and toss it into every scene you make?
I ask because I realized some of my managers don't need to follow the player (no global variables, stats, etc), but need to be in every scene. I imagine that just making them DontDestroyOnLoad will reduce load time because you're loading them at the start of the game and never again, but maybe there is something behind DontDestroyOnLoad that makes it use more memory in the long run.
Anyone have an idea on this?
Keep in mind, I know I will still have to have a StateManager of some sort that will have to use DontDestroyOnLoad so I can keep track of stats, variables, etc.
Answer by Julien-Lynge · Nov 30, 2013 at 08:07 AM
It's definitely good to be thinking about performance, but for what you're describing the difference is so negligible - a few ticks of time, probably only a few kB or MB of memory - that it really doesn't matter. It's much more important to go with whatever is going to make your job easier designing your game. If you have information that you need to keep between scenes, you could either use DontDestroyOnLoad or you could, for example, store the information in static variables so that any manager that's instantiated has access to them.
Personally, I like the second option, because it means that during development I can go directly into any scene without having to go through the main scene and instantiate my DontDestroyOnLoad object first.
Thanks again @Julien.Lynge. I didn't see much on whether or not it mattered so thought I'd ask and put it out there.
Looks like I'll stick with the persistent managers and just have them load once on game start.