Tutorial: Load additive scene 
In this tutorial, we will see how to load and unload additive scene with INTERACT physics in runtime. This can be useful when you want to set up a menu scene in which you can select to open different Interact simulation or training scenario.
Setup your additive scenes
- Create your menu scene which is not an INTERACT Simulation, i.e. home_scene in this example.
- Create an INTERACT Simulation, i.e. physics_scene in this example.
- Use the loadAdditiveScene.cs script given in example below in your menu scene. It can be added to any GameObject.
-
Make sure the scenes you want load in runtime are added to Scenes in Build Settings.
-
In runtime, use the context menu on the loadAdditiveScene component you added in your menu scene to load another scene.
- This will open your physics_scene in runtime.
- You can close the physics_scene and open it again using the context menu to restart this simulation.
Script Sample
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using Interact.Simulation;
public class loadAdditiveScene : MonoBehaviour
{
[ContextMenu("Open Scene")]
public void OpenScene()
{
SceneManager.LoadSceneAsync("physics_scene", LoadSceneMode.Additive);
}
[ContextMenu("Close Scene")]
public async void CloseScene()
{
await InteractPhysicsManager.Instance.StartServers.StopServer(InteractPhysicsManager.Instance.StartServers
.XdeServer);
SceneManager.UnloadSceneAsync("physics_scene");
}
}