Unity: What Is a Scene

December 27, 2023

A scenes acts like a binder that binds game objects together.

Without a scene, there’s no game. Therefore, as a game developer, it is essential to have substantial knowledge of scenes. In this article, I’ll dive deeply into all you need to know about Scenes in Unity.

What is a Scene?

Scenes contain the environments and menus of the game. It represents the level or stages in your game. Each scene in a game contains the environment, characters, obstacles, decorations, and UI.

A simple game can have just a single scene, but a complex game should have multiple scenes to represent levels or stages in the game.

In some games, they split gameplay, environment, and UI into separate scenes, then load the scenes dynamically to build a final combined scene for the project.

When you create a new project in Unity and open it for the first time, there’s a sample scene available for you that contains only a main camera and a directional light.

Creating New Scenes in Unity

There are different ways of creating new scenes in Unity:

From the New Scene Dialog

The New Scene Dialog opens by navigating to New Scene in the File menu or by the shortcut (Ctrl/Cmd + n). To create a new scene:

  1. Select a template from the list of templates shown on the New Scene Dialog.
  2. Click Create to create a new scene from the chosen template.

From the Menu

Without opening the New Scene Dialog, you can create a new scene directly from the menu by navigating from Assets to Create and then to Scene.

From the Project Window

You can use the context menu in the Project window to create a new scene. To do this:

  1. Navigate to the folder where you create the new scene.
  2. Right-click the folder in the left-hand pane.
  3. Click Create > Scene from the context menu.

From a C# Script

To create a new scene using C# during runtime, use the CreateScene method.

using UnityEngine.SceneManagement;
using UnityEngine;

public class ExampleClass : MonoBehaviour
{
  void Start()
  {
    CreateNewScene("MyNewScene");
  }
  
  void CreateNewScene(string sceneName)
  {
    Scene newScene = SceneManager.CreateScene(sceneName);
  }
}

To create a new scene using C# during Edit mode, use the NewScene method.

using UnityEditor;
using UnityEditor.SceneManagement;

public class SceneManipulator
{
  /// <summary>
  /// Creates a new empty scene using the Unity EditorSceneManager.
  /// </summary>
  
  public void CreateEmptyScene()
  {
    var newScene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Additive);
  }
}

Loading Scenes

Now, you know how to create a new scene in Unity. How do you open a scene you have created?

  1. Double-click the scene in the project window.
  2. Navigate to the scene in the Recent Scenes pane in the File menu.

Saving Scenes

It is important to save the scene you’re currently working on so you can refer to it later. To do this:

  • Click on Save Scene from the File menu.
  • Use shortcuts; (Ctrl + S) for Windows and (Cmd + S) for MacOS.

Working with Multiple Scenes

You can work with multiple scenes in a project in Unity. To add one or more scenes to your project:

  • Drag one or more scenes from the Project window into the Hierarchy window.

You can now view the scenes from the Hierarchy window, which displays all the scenes that are part of your project.

Conclusion

Now that you understand the intricacies of scenes in Unity, you can try out all you have learned in this article as soon as possible. For more information, you can visit the Unity documentation.

Want to build better games?

© 2024