Hi, all-- I'm trying to figure out the best way to implement 'levels' in a game I'm working on. So let's say, as an example, you're workin' on a puzzle game of some sort where from level to level the game board changes, but everything else (environment, camera, lights, etc.) stay the same. I'm assuming that rather than create a scene for each level, you'd just reuse the same scene and re-initialize the game board and 're-start' the scene? And also, for future reference, if you did create a scene for each level in a game where only a few things were changing from level to level: if you duplicate a scene and just change the elements that are different between the two scenes, will Unity basically re-use the assets that are 'shared' between scenes? Thanks! Bryan
I've used a couple of approaches. Create a scene for each level. Make the UI and background a prefab. Any updates to the prefab will update across all levels Build the UI and background in a preloader scene. Call DontDestroyOnLoad so the stuff stays persistent as you change scenes Build everything in one scene. Manually control loading and destroying objects Assets are reused. However Unity will remove the specific GameObjects from memory and create new ones.
I just wanted to highlight this as one of the "best" ways of doing it in Unity. A big advantage of this is that the preloader scene is essentially a "prefab" object that can contain other prefabs. So if you have several UI screens in different scenes but they all share similar elements (prefabbed buttons, widgets, etc), then you can just modify one and all of them will be updated. Nested prefabs like this are not natively supported in Unity but having a preloader scene works extremely well for this and is easy to implement.
Can I just ask in relation to this, I'm thinking about same things as op, when I call don't destroy on on a scene and swap to another, does the "background scene" stop running? EG if I have 5 scenes paused for example it's not taking up resources apart from RAM GPU video RAM? So frame rates stay constant?
There's no such thing as a "background scene"; a "scene" is really just a bundle of objects loaded together, so loading a new scene is only "swapping" scenes in the sense that normally everything from the previous scene is unloaded. Anything loaded is actively being used and is in RAM (indeed, that's what loaded means). You can choose to SetActive(false) on the objects you want hidden, but a) that's on you to do, and b) if you're going to do that then I don't understand why you didn't just let them get flushed like normal.