So I’m so close to finishing Escape the sector, and it’ll either be released on the Android Play store, or abandoned in a fit of rage!
I’ve enjoyed working on it, but it’s been frustrating. I’ll post a full debriefing soon with my thoughts on how it went, but right now I’m refactoring the way it loads levels because it’s really slow.
The way it works is to have all levels in one Unity scene, then hide the ones we aren’t using, and show the one we are. It means I don’t have to worry about loading the player, UI, and all other shared components into many scenes. Problem is, it loads all levels in one go, even ones you’re not playing, and that takes a long time, especially on mobile.
So I chatted with some Unity developers on the Facebook group, and on Twitter also, and it looks like a common method to use would be the “singleton pattern” which is where the gameController is loaded once in a scene, and if it’s ever attempted to be loaded again (at the start of the next scene), don’t load it because you already have one. That means you can use LoadLevelAsync to load a level into the level you’re already in, which has the benefit of being able to show loading progress – right now the level just hangs until the new scene is loaded, which means I can’t even show a loading spinner, as it just stays motionless.
I’m going to cheat a bit
For the sake of quickness, and because I didn’t build this game thinking about loading stuff asynchronously from the start, I’m going to cheat, and instead of loading asynchronously, I’ll load each level normally, but make sure each of my levels is in a separate scene with a single GameController.
I do have to make changes though, which involves making any UI element, like game over messages, or instruction messages etc, a child of this gameController. I’ll do this because then the gameController object can be a prefab, and if I ever make a change, I can update every level’s gameController at once, rather than opening each scene individually.
LevelsController
The GameController I mentioned won’t be a singleton, but I will have a separate object (I’ll call it LevelsController) which will persist through all scenes (dontDestroyOnLoad) and do important things like remember the level we’re on, and load the next level. It’ll also be important for saving progress, and populating a menu screen, but in this project I’ve already done that as part of another script and I don’t want to reinvent something that actually works!
I’m happy with the progress so far, despite it taking long time. I’ve thought about stopping this at only 3 levels, because sometimes I look at it and hate it, but recently I’ve shown it to 2 people who said positive things about it, so I’m going to continue and make a few more levels, probably 6 in total.
The extra effort put into loading levels properly won’t be wasted anyway, it’ll be used in my next project.
I’ll keep you posted, and make sure you follow me on twitter @davidonionball – I occasionally tweet about needing alpha and beta testers!