Four scenes Unity project template
When you develop a video game, sometimes you create the prototype, then you think about making it a real and complete game.
Where do I have to optimize it, how to switch from one level to another, hey it’s freezing between the levels, how am I going to make it smooth for the players??!
Well, few assets can make your life easier. The Four scenes project template is one of them, it is free and available from the end of this post. Here’s why it’s so useful.
This asset was created as a legacy from the indie games studio I created in 2012. These are not the exact same sources as the one used during its 6 working years, but an evolution of those.
Why four scenes?
When your Unity game is launched, the OS has to load the Unity engine first. While it’s doing so, you only have the splash screen shown, that is your logo and/or the Unity logo, with a little animation if you’re lucky.
After that, your first scene is loaded, and every shared resource is also loaded. Once they are loaded, all game objects of your first scene are activated, and all Awake and Start and OnEnable methods are called and executed.
Only after all that has happened, the first scene is displayed to the player. That can be a loooooong time, believe me! If you build an iOS game, it can even cause your app to be killed by iOS because it’s taking too long before showing anything to the user (been there..).
So the solution is to split your first scene into pieces, but not only in two pieces. Here are the scenes I put in every project I developed once I understood that.
The first scene: static loading
The first scene has to be minimalist: think about another splash screen and one script. This is your entry point, to tell the player and the OS that the engine has been loaded and this is the game going on now.
This scene is there to take the player one step further: you can have an animated splash screen, detect the hardware performance to redirect toward the SD or HD quality settings, but that’s all.
In the template, there’s a canvas and a blurry background image. Nowadays, it’s not as required as before, but it’s a trick for low-end devices: use a blurry image with a lower resolution to use less memory and improve performance.
There’s only one custom script and it’s there to load the next scene.
I don’t add custom shader, fancy code nor specific very optimized code when it’s not required.
Since my first coding project a while ago, and specifically, since 2007 when I started to use Unity, just using correctly the engine or development environment is the correct answer.
Like Thomas said: use your favorite tools!
And I also add: use and learn them until you can’t learn anymore, only then you will be able to get the most out of them.
Minimalist is the keyword here.
The second scene: asynchronous loading
In the second scene, we go a little fancier: we load a transition UI and an asynchronous loading script that allows displaying a loading progress bar to the player!
The Transition is a prefab and a singleton from my Standard Assets that exists in two flavors: a transition with animated panels, and a cut-out image with a specific shader.
The loading script is improved to handle the transition prefab to be shown when the scene is loaded but before it’s activated. Once activated, the transition will be hidden automagically. Bless the event handler (also included in the Standard Assets package). Of course, the progress bar is updated from an event triggered by another script that monitors the scene loading operation.
I’ve also added a tips manager so the player starts to see something interesting: he can learn something and is not bothered anymore by some logo or still screen.
Tips are included in text files that are exported in Asset Bundles.
Those are not yet managed as remote assets in the demo, but this will be included in a future release.
Still, this scene is quite simple but allows us to climb one more step.
From that scene, the player is not waiting anymore in front of a static screen, and we can break on through to the other side…🎵
The third scene: data loading
This scene can be the first huge scene in your project (well, be careful there). If you have large assets that will be used in every other scene of your game, this is the scene where you have to put them. In the template, I’ve included an object pool with some sample assets, just to show you how to handle them.
Music, audio sources, resources, and every game-specific checking script you want to do can happen here.
Remember: when this scene is displayed, that means that everything in this scene has already been loaded!
And the last advice but not the least: this scene is the last one that will be loaded only once in your game. Every asset loaded here won’t be loaded again, and you must never go back to this scene from your game.
The fourth scene: menu
This can be replaced by any scene you want, but a lot of games have a menu so I decided to include one here. This is a simple main menu scene with an animated play button. To use it right away, search for the object named PlayButton and change the scene name to whatever you want to load after this one. By default, this loads the game scene.
In the menu, I’ve included some fancy stuff :
- scrolling tiled image in the background
- animated play button
- vignetting using a simple foreground image
Test it
Packages are available free from my GitHub repository.
To use those four scenes, just include them in the correct order in your build settings: they are prefixed by a number so it should not be that hard.
This template uses some of my other free standard assets, available from the Unity asset store and from my GitHub repositories also.
If you decide to use them for a project, a game jam, or anything, tell me if that helped you or if anything can be changed. I will make this template evolve to fulfill my new game projects and could include yours!
Thank you for reading until here and write to me on FredericRP.com!