Retaining and switching scenes at runtime

Hi,

I’m making a Total War: Rome style game, where the main gameplay is a turn based strategy game, but I also want 3rd person real time strategy battle scenes to occur when two armies meet. I’m curious as to how to switch between the turn based game, and the RTS battles in Unity? My initial thought was have a generic RTS battle scene and load that scene when you want to play a battle, which is fine. The part i’m struggling to think of a solution for is switching back to the turn based game, once the RTS battle scene is over? To be clear, I have no problem retaining data between scenes (I use singletons etc), its just the load times involved in scene loading i’m worried about. Ideally I would like to keep the turn-based scene loaded, paused and hidden in the background while i’m playing the RTS scene, and then switch back. Not sure how to do this though, or where to begin really. The only way I can think of how to do it at the moment is to simply save the state of my turn based game prior to the battle scene, and then load a new turn-based scene with the saved data once the RTS scene is over? The problem is, that is essentially saving and loading my entire game each time, which may be too slow for battles that may occur regularly?

Can someone point me in the right direction as to how to handle this in Unity? Do I just have to stick to saving and loading turn-based scenes before/after each battle scene, or is there a better way?

Thanks, guys!

Put everything in the turn based scene under a single GameObject, likewise put everything in the RTS scene under a single GameObject. Then when you want to hide one, just set the related root GameObject to inactive. If you want to ‘unload’ one, Destroy the related root GameObject. When you want to load one, just load it additively.

1 Like

Thanks Antony. I may have to do it that way. Do you know if there is any other way to do it in Unity?

I don’t believe so, once you’ve loaded a scene additively there’s no way to later determine which objects came from which scene to unload/hide them unless you do it some other custom way. What I suggested above would be the easiest way to go I think.

Will that not work for you in this case? If so why not? Maybe I can think of something else.

No I’m sure it will work, I’m just trying to get a grasp of all the options first before I make a decision in which way I’ll proceed. Ideally I’d like to keep the scenes separate, but it’s not mandatory that I do. I’m sure there are plenty of games that do something similar to what I’m trying to do (i.e. a game within a game), so was just after some feedback on the best way to approach it in Unity.

Oh, I think you’ve misunderstood me. You can keep the scenes separate. But just be sure that everything in each scene is under a single GameObject so that when they are loaded in additively everything from that scene is all grouped under that GameObject.

Funny I just came here to ask about a feature coming in Unity 5.3 ( December 8th). There was mention in a blog from a year ago that with Multiple-Scene editing, that there will be a new method to unloadscene. Multiscene Editing is coming in December, but I have not seen anywhere mention if the unloadscene function is still a part of it. This will be a bit cleaner than destroying a gameobject that contains everything from a scene.

To be honest I think this is a pretty clean solution. All you need it 1 more GameObject per scene and it helps you debug things at runtime as all the objects will be nicely organised into their scene hierarchy.

You can also get Unity to unload the assets you just destroyed and are no longer referencing by calling Resources.UnloadUnusedAssets(); when the time suits you.

Well we don´t know the details of how unloadscene will function, but it probably does all that without the requirement of you putting everything under an empty game object or destroying it at once. We don´t know the details, but it is certain that at least it will exactly mimac what you already mentioned.

Thanks for the feedback guys. I’m going to go with Antony’s suggestion. Unloading scenes will be a nice feature! Looking forward to that.