Load and unload scenes at runtime

The following code loads three scenes and adds them as children:

  1. var myChildScene0 = Content.Load<Scene>(url0);var myChildScene1 = Content.Load<Scene>(url1);var myChildScene2 = Content.Load<Scene>(url2);myParentScene.Children.Add(myChildScene0);myParentScene.Children.Add(myChildScene1);myChildScene1.Add(myChildScene2);
Note

root assets (indicated with blue icons in the Asset View). Asset View, right-click the scene asset and select Include in build as root asset. Manage assets. Manage scenes.

Scene streaming script

trigger to load scenes.

Note

The scene streaming script is included as an example. It isn’t always the most appropriate way to load scenes. Feel free to modify it as much as you need.

Add a scene streaming script

Asset View (bottom pane by default), click Add asset and select Scripts > Scene streaming. Game Studio adds a scene streaming script to your project assets.

Use the scene streaming script

  • Triggers. Colliders.
  • Create an entity and position it where you want the scene to load.
  • Property Grid (on the righy by default), click Add component and select the scene streaming script.
    Note
    If the scene streaming script doesn’t appear in the list of components, reload the assemblies. Game Studio adds the script to the entity as a component.
  • Url, specify the URL of the scene you want to load.
  • Trigger, specify the entity you created in step 1. At runtime, when the trigger you created in step 1 is triggered, Xenko loads the scene you specified in step 4.

    Scene streaming script properties

    See also

  • Colliders
  • Triggers
  • Create and open a scene
  • Navigate in the Scene Editor
  • Manage scenes
  • Add entities
  • Manage entities