About 'Load All Scenes'!


In this video (objectives)…

  1. Create new method to load straight to our first scene.
  2. Hook up all buttons to loading functionality.
  3. Load all scenes.

After watching (learning outcomes)… Load all scenes in our game using buttons.

(Unique Video Reference: 6_UI_CUD)

We would love to know…

  • What you found good about this lecture?
  • What we could do better?

Remember that you can reply to this topic, or create a new topic. The easiest way to create a new topic is to follow the link in Resources. That way the topic will…

  • Be in the correct forum (for the course).
  • Be in the right sub-forum (for the section)
  • Have the correct lecture tag.

Enjoy your stay in our thriving community!


There is an alternative to creating LoadStartScreen. I found the SceneManager.sceneCountInBuildSettings. we can use this as modulus for calculating the next scene index.

So instead the LoadNextScreen becomes

public void LoadNextScene() {

    int CurrentSceneIndex = SceneManager.GetActiveScene().buildIndex;

    SceneManager.LoadScene((CurrentSceneIndex + 1) % SceneManager.sceneCountInBuildSettings);

The assumption being that you are always going to load the next sceen in the index. The % is a modulus so when we get to the last schene index (2) the next scene index becomes (2+1)%3 = 0


Yep, thats a good way to do it. I didn’t want to introduce modulus at this point in the course so I did it in more of a direct manner.


Hey i did something like that (did add another script just for last scene) can i still use it or will it cause issues later on?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class restart : MonoBehaviour {

public void LoadNextScene()
    int currentSceneIndex = SceneManager.GetActiveScene().buildIndex;
    SceneManager.LoadScene(currentSceneIndex - 2);


Your solution is excellent I never thinked about to use the modulus.


My solution to how to load all scenes is this

In the if I check if the index of the scene is not the last. If it’s not then load the next scene else load the first scene.

But the solution from @Paul_Simmons is the best solution because it can be written with a single line of code. Congrats to you :clap:


Yes it will cause an issue with the first scene. The problem here is when you are at the first scene, which has the index of 0, when you try to load the next scene you do
0 - 2 = -2.

The index of the scenes starts from 0 and there aren’t any negative indexes values in the Build settings.


Modulus is amazing … it is useful in so many circumstances. I mainly use it for partitioning, e.g. I want 3 buckets and things to be distributed in them randomly becomes

bucket = random % numBuckets;