Skip to main content
Product: Molca VR SDK
Primary script: Assets/_MolcaSDK/_VR/Scripts/Scenario/Session/ScenarioSessionManager.cs

Goal

Run one complete backend session flow:
  1. Wait runtime initialization
  2. Create session
  3. Load/start scenario
  4. Observe progress/error events
  5. Enter playable scenario scene

Prerequisites

Implementation checklist

using Molca;
using MolcaSDK.VR.Scenario.Session;
using UnityEngine;

public class SessionBootstrap : MonoBehaviour
{
    private ScenarioSessionManager _session;

    private async void Start()
    {
        await RuntimeManager.WaitForInitialization();
        _session = RuntimeManager.GetSubsystem<ScenarioSessionManager>();
        if (_session == null) return;

        // Subscribe early for diagnostics
        _session.OnError.AddListener(OnError);
        _session.OnLoadingProgress.AddListener(OnProgress);

        var created = await _session.CreateSessionAsync(orgScenarioId: 42, mode: "TRAINING");
        if (!created) return;

        // Pick one per UX:
        // await _session.LoadSessionWithModalAsync(...);
        // await _session.LoadSessionWithProgressAsync(...);
    }

    private void OnDestroy()
    {
        if (_session == null) return;
        _session.OnError.RemoveListener(OnError);
        _session.OnLoadingProgress.RemoveListener(OnProgress);
    }

    private void OnError(string msg) => Debug.LogError(msg);
    private void OnProgress(float value, string status) => Debug.Log($"Load {value:P0} - {status}");
}

Troubleshooting quick checks

  • Create session fails: verify token/auth stage and org scenario id.
  • Progress never moves: confirm scenario scene/addressable keys and content package availability.
  • Scene loads but training doesn’t start: verify Scenario manager scene wiring and data config linkage.