Scene Assets

    There are three ways to create a Scene:

    1. Select the folder to create the Scene file in the Assets panel. On the folder right-click and select Create -> Scene, and then type the desired Scene name.

      In order to have a good directory structure in the project, it is strongly recommended that use this method to create a Scene.

    2. Click the Create (+) button in the upper left corner of the Assets panel, and then select Scene.

      new_scene_2

    Method 1: Use the shortcut keys Ctrl + S (Windows) or Command + S (MacOS) to quickly save the scene.

    Method 2: Select File -> Save Scene in the top menu bar.

    In the Assets panel, double-click the Scene to be opened.
    When needing to switch Scenes in the game, use the API to implement dynamic scene loading and switching in the game.

    After double-clicking to open the scene file, the is the root node of the scene node tree in the Hierarchy panel. Select the scene node, and set whether the scene is automatically released or not in the Inspector panel, as well as the whole scene related properties, including ambient light settings, shadows settings, global fog and sky box settings.

    scene_node

    Automatic release of scene assets, please refer to section Change the policy of auto releasing assets from previous scene below for details.

    In a large game where there are many scenes, as the engine continues to load different scenes, the memory usage will continue to increase. Besides using API such as to accurately release unused assets, one can also use scene’s auto releasing feature.

    After double-clicking to open the scene file, select the scene node in the Hierarchy panel to set whether the scene is automatically released in the Inspector panel:

    When switching from current scene to the next scene, if current scene disabled the auto releasing, then all assets (directly or indirectly) referenced by current scene (except loaded dynamically in scripts) will not release by default. On the other hand, if enable the auto releasing, then these assets will release by default.

    With the auto releasing enabled for a scene, if some of the scene’s assets are saved in the script as “special reference”, these references will become invalid once the scene switched, since the asset has been released, may cause rendering problems. To prevent these assets from being released automatically, we can use to retain them.

    “Special reference” refer to references in the form of global variables, singleton, closures, “dynamic assets”, and so on.
    “Dynamic assets” refer to assets that are dynamically created or dynamically modified in a script.

    The above content of the automatic release of scene assets can be summed up in the following diagram of several cases:

    For additional information on asset release, please refer to the Release of Assets documentation.