Loading the Scene

As shown in the Entry Point guide, to get our scene, we use the IResourceManager to load our scene.

Loading Resources

The asset interface for Scenes is ISceneAsset. Loading is very straightforward, and we will once again use modern C# async and await.

using SDT4.Managed.Core;
using SDT4.Managed.Core.Asset;
// ...
AppInstance instance = /*...*/;
IResourceManager resourceManager = instance.ResourceManager;
// Use use AssetID for referencing assets.
var sceneAsset = new AssetID("Master/MyScene.sdt");

// LoadAssetAsync<TResource>() returns a Task on which we can await the ISceneAsset.
var mySceneResult = await resourceManager.LoadAssetAsync<ISceneAsset>(sceneAsset);
// ...  

Instantiating the scene

Once the scene asset has been loaded, it is time to instantiate it. This is seperate from loading for the following reasons:

  1. It allows restoring scene state quickly without reloading the entire asset
  2. It enables easier management of multiple concurrent scene load operations.
// ...  
// You should check load results, however for the sake of brevity, 
// we will assume it loaded correctly.
Scene scene = mySceneResult.Resource!.CreateScene();
// Start() initialises the scene script. This must be performed on the main thread!
scene.Start();
// scene.StartAsync() is an alternative, and allows concurrent ticking.
// ... 

Danger

Any calls to the Scene object MUST be performed on the master thread.