Skip to main content
Applies to: Molca VR SDK

Overview

This recipe shows you how to create a complete VR training scenario from scratch. You’ll create a Scenario Data Config asset, set up a scenario scene with ScenarioManager, add activities with VR-specific steps, and configure the session flow. This is the foundation for building immersive VR training experiences with ordered tasks, scoring, and backend integration.

Prerequisites

  • SDK modules: Molca Core, Molca VR SDK installed
  • Unity setup: RuntimeManager configured, XR Plugin Management installed, GlobalSettings configured
  • Prior knowledge: RuntimeManager, SequenceController, Step

Step-by-step

Step 1: Create a Scenario Data Config asset

Create a ScenarioDataConfig asset to register your scenario collections and configure execution mode.
Why this works: The ScenarioDataConfig is a SettingModule that tells the runtime which scenarios exist and how to resolve them by ID. It’s loaded during RuntimeManager initialization and used by the session system to find scenario assets.

Step 2: Create a Simulation Scenario Data asset

Create a SimulationScenarioData asset that defines your training scenario metadata.
Why this works: SimulationScenarioData holds the metadata that links your scenario asset to its Unity scenes via the SceneLoadPlan structure. The RefId is used for local lookups, while ScenarioId (org ID, set later) links to backend scenarios. The SceneLoadPlan supports ordered multi-scene loading — preload scenes load first (environment, shared assets), then the main scenario scene.

Step 3: Add the scenario to ScenarioDataConfig

Add your scenario data asset to the ScenarioDataConfig collections.
Why this works: The ScenarioDataConfig uses collections to register available scenarios. At runtime, methods like GetScenarioDataByScenarioId search these collections to resolve scenario references.

Step 4: Create the scenario Unity scene

Create a new Unity scene for your VR scenario and add the VR Scenario prefab.
Why this works: The [VR Scenario] prefab provides the complete VR runtime infrastructure: XR Origin for tracking, ScenarioManager for orchestration, scenario UI for pause/completion, and player management. This ensures consistent VR setup across all scenarios.

Step 5: Configure ScenarioManager

Select the ScenarioManager component in your scene and configure it to reference your scenario data.
Why this works: ScenarioManager is the runtime orchestration component that manages scenario state (Inactive, Active, Completed), drives activities in order, and integrates with the session system. The scenarioData reference links the scene to your scenario metadata.

Step 6: Create activity GameObjects

Under the ScenarioManager, create child GameObjects for each training activity.
Why this works: Each ScenarioActivity wraps a SequenceController and integrates with scoring and session posting. The activityId field links the runtime component to backend activity metadata when using connected sessions.

Step 7: Add VR steps to activities

Create child GameObjects under each activity and add VR step components.
Why this works: VR steps are specialized Step subclasses that handle VR interactions. LookAtStep completes when the user gazes at a target for a duration. GrabStep completes when the user grabs a specific object. The SequenceController executes these steps in hierarchy order.

Step 8: Wire activities to ScenarioManager

Add your activity GameObjects to the ScenarioManager.activities array.
Why this works: The ScenarioManager executes activities in array order (unless startAllActivitiesSimultaneously is checked). When an activity’s sequence completes, the manager advances to the next activity or completes the scenario.

Step 9: Configure session flow (optional)

For production scenarios with backend integration, configure the session flow.
Why this works: ScenarioSessionManager handles backend session creation, scene loading via Addressables, and progress tracking. The CreateSessionAsync call establishes a session with the backend, and LoadSessionWithProgressAsync loads the scenario scene and starts the training. This flow requires useSessionManager to be checked on ScenarioManager.

Complete example

Here’s a complete custom VR step that waits for the user to press a button before completing:
Attach this script to a child GameObject under your ScenarioActivity, and it will wait for the user to interact with the specified button before advancing.

Troubleshooting

  • Scenario never starts: Ensure RuntimeManager.WaitForInitialization() completes before calling StartScenario(). If using autoStart, verify the ScenarioManager is active in the scene.
  • Activities don’t advance: Check that each activity’s SequenceController is properly configured and that steps call Complete() when finished. Use the Sequence Visualizer to debug step hierarchy.
  • Session creation fails: Verify ScenarioNetworkConfig endpoints are correct, authentication token is valid, and orgScenarioId exists in the backend. Check OnError event logs.
  • Scene doesn’t load: Confirm the SceneLoadPlan is configured in SimulationScenarioData — check that singlePlayerPlan.scenarioScene has either sceneName or sceneReference set. For Addressables, verify the scene is marked as Addressable and the key matches exactly.
  • Steps execute out of order: Steps execute in hierarchy order (top to bottom). Reorder GameObjects in the Hierarchy or check for parallel step configurations.
  • Preload scenes don’t load: Verify singlePlayerPlan.preloadScenes array is populated. Index 0 loads as Single (active scene); subsequent entries load Additive. Check console for scene load errors.
  • Scene loads but objects missing: Check waitForRefIds on preload scene entries — the executor waits up to 15 seconds for those RefIds to be registered in ReferenceManager. If timeout occurs, check console warnings.