Loading Scenes in Unity

Dominique Dos Santos
3 min readApr 5, 2021

Today we’ll be talking about loading scenes in Unity. When you think about it almost every game is made up of different scenes. These scenes could be Menus or different levels or different parts of a game. The bigger the game the more likely you’ll have to load through different parts of the game.

If you take a game like The Elder Scrolls Online. It’s defined as an open-world game, but when you play you don’t load that entire map, but rather sections of it. When you’re in a village and you enter a building, it loads up a different scene just for that building.

Scenes in our Space Shooter Game

In our game right now we have only been working with one scene which is the Game. But when someone plays your game they don’t want to be just thrown in and having to figure out how the game works. You rather want them to be greeted with the Main Menu. This allows the user to learn more about your game with a screen with controls and how to play, and when they’re ready, they can click the “New Game” button and load up the game scene.

Loading Scenes Through Code

When you want to load a scene there are a few ways to achieve this. My preferred route is using an “Async” function. This allows you to create loading scenes with moving parts or a progress bar. I created a GameManager Script and added a public function that I can call wherever I might need it. I’ve also created a Coroutine wherein I have my Async loading.

Please note that when you work with scenes that you need to add the “using UnityEngine.SceneManagement;” to your libraries to use the “SceneManager” Naming.

Making the Button Work

Once the button has been created, renamed and moved to your desired position then it’s time to add the function to the button. You’ll see it’s actually straightforward.

Wrapping Up

And just like that we have the Main Menu set up and when you play and click the “Start Game” button, it will load the Game Scene and you can now play the game.

--

--

Dominique Dos Santos

Self-taught Unity and C# Developer with a passion for games and the stories they tell.