Change scenes manually

    GDScript

    C#

    To complete the cycle and swap out the new scene with the old one, developers have a choice to make. Many strategies exist for removing a scene from view of the . The tradeoffs involve balancing operation speed and memory consumption as well as balancing data access and integrity.

    1. We can delete the existing scene. SceneTree.change_scene() and will delete the current scene immediately. Developers can also delete the main scene though. Assuming the root node’s name is “Main”, one could do to delete the whole scene.

    2. We can hide the existing scene. By changing the visibility or collision detection of the nodes, we can hide the entire node sub-tree from the player’s perspective.

      • Memory still exists.

      • Processing continues.

        • Pro: Nodes are still members of groups (since groups belong to the SceneTree).
        • Con: The CPU’s attention is now divided between both scenes. Too much load could result in low frame rates. One should be sure to test performance as they go to ensure the target platform can support the load they are giving it.

    There are also cases where one may wish to have many scenes present at the same time. Perhaps one is adding their own singleton at runtime, or preserving a a scene’s data between scene changes (adding the scene to the root node).

    GDScript

    C#

    Perhaps instead they wish to display multiple scenes at the same time using a . This is optimal in cases where the intent is to render different content in different parts of the screen. Minimaps and split-screen multiplayer are good examples.