CodeBlanks Logo Icon CodeBlanks

Build Settings

Learn to add and order scenes in Build Settings.

Build Settings and Scenes In Build

Which scenes are packaged into the final game executable and loadable through code is configured in File -> Build Settings. Scenes absent from the Scenes In Build list are omitted from the compiled project and cannot be accessed at runtime.

// Scene index and build list
// File -> Build Settings -> Add Open Scenes

The Add Open Scenes button quickly registers whichever scene is currently open in the editor into this list.

Build Index and Startup Scene

Each scene in the Scenes In Build list receives an integer (Build Index) starting from 0. The scene placed at the very top with index 0 automatically serves as the initial scene when the game launches.

// Scene at index 0 is the entry scene
// Index 0 -> MainMenu.unity
// Index 1 -> Level1.unity

Typically, main menus or intro logos are placed at index 0 to kickstart the gameplay flow.

Practice Print scene index and name

Assign 0 to sceneIndex and "MainMenu" to sceneName. Print Index: 0 | Scene: MainMenu to the console.

Starter code

Player.cs
using System;

class Program
{
    static void Main()
    {
        // sceneIndex ve sceneName değerlerini tanımlayıp yazdır
    }
}

Sample solution

Player.cs
using System;

class Program
{
    static void Main()
    {
        int sceneIndex = 0;
        string sceneName = "MainMenu";
        Console.WriteLine("Index: " + sceneIndex + " | Scene: " + sceneName);
    }
}

Expected output

Index: 0 | Scene: MainMenu

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Where must a scene be registered to be included in the compiled game package and loaded via code?

  • In the Scenes In Build list within the Build Settings window Correct answer
  • In the SFX channel under the Audio Mixer panel
  • Inside the Culling Mask setting of the Camera component
  • At the top of the Hierarchy window

Explanation: The Scenes In Build list is the official registry of scenes included in builds and accessible through script calls.

2 Read active scene build index

Question
int currentBuildIndex = SceneManager.GetActiveScene().____;
Answer
int currentBuildIndex = SceneManager.GetActiveScene().buildIndex;

Explanation: The numeric order of a scene in the Scenes In Build list is accessed via the buildIndex property.

3 Build Settings concepts

Term Meaning
Build Settings Window for target platform & scene list
Scenes In Build Indexed list of scenes in the build
Build Index 0 Initial scene loaded at game start
Add Open Scenes Button adding open scene to the list

All lessons in Intermediate