Hi, I’m Chantelle, the lead coder on Dead Exit (although my official title is Slaughter Coordination Engineer). Today I’m going to explain a little about how we manage scenes in Unity.
Dead Exit is set on an abandoned rooftop in the middle of a zombie apocalypse. So when we were building the game, we created a single environment prefab with the idea that for every scene within the game, the camera would focus on a different view of the environment. This idea went through many different iterations before I was happy with the system; one that was easy for everybody to use and loaded at a reasonable speed.
Our previous game, The Living Dungeon, used a system which switched to an individual scene for each area of the game, such as the frontend menu and game. This worked fine because we didn’t have any persistent objects (other than managers and the like) between the scenes. So we tried this method initially in Dead Exit; each scene had a copy of the environment prefab and all of the other relative managers to make it functional. This worked, but it wasn’t exactly easy to use. The environment was a prefab so it was totally fine modifying things in there, but when we wanted to change something like the lighting for example we had to try and copy across every variable/data file between each of the scenes using the environment prefab. It was generally just a really annoying and tedious system.
So the next thing I tried was having a single scene which had everything we would require in it. It had the environment prefab, and then a bunch of prefabs which represented each scene; Engagement, Frontend, Game, etc. Each prefab was then activated/deactivated depending on which “scene” we wanted to go into. This was better because if we were never changing the scene, managers wouldn’t have any reason to complain and we didn’t have to redo data for lighting or cameras. But the loading times were really, *really* bad. Every single prefab we used in the game scene, and every other scene prefab existed straight away in a single scene, so obviously it would take time to load that main scene. It was even worse when we tested it on a console! We could have moved assets to the Resource folder to reduce loading times, but this would have presented problems on consoles in the future.
Finally, after watching some Unity tutorials and live training sessions, I stumbled across and decided to modify the scenes so they were loaded in additively. Loading a scene additively means other scenes can be loaded on top of/into your current scene. So this time, I created a persistent scene which had the environment prefab, all of the managers and anything else which would be required globally, but none of the specific controllers for each area (like the Game controller). Then I again created scenes for each area, such as Frontend, Game, etc, but this time they just had the scene prefabs I created previously in them. These generally consisted of a UI prefab and a controller prefab. Now I would always have the persistent scene loaded and could load the relevant scene in additively.
Previously I mentioned how we wanted the camera to focus on different parts of the environment depending on what area of the game we were in. To achieve this using the current setup I only need a single camera instance located inside the persistent scene. When another scene is loaded in, it sends an event to the camera which animates it to the requested position and rotation. This means we don’t have to have multiple cameras per scene and attempt to have them synced at the start and end of a scene change.
I’m really pleased with how scene management is handled in Dead Exit now. From a developer perspective, it’s very easy to modify individual areas of the game without affecting or causing issues anywhere else. And from a gameplay point of view, I feel it creates a seamless experience transitioning between the different areas of the game. For more information about loading scenes additively, this tutorial was the thing which formed the basis of our scene management system. I know this blog has been pretty abstract, but I hope if you’ve been thinking about how to manage your scenes it’s given you an idea about the different ways you can utilise Unity to create what you’re after. If you’d like me to follow up, or go into detail about the code behind the scene manager, you can tweet us @RadiationBurn or send us a message on Facebook.