Applies to: Molca VR SDKDocumentation Index
Fetch the complete documentation index at: https://docs-unity.molca.id/llms.txt
Use this file to discover all available pages before exploring further.
Overview
This recipe shows you how to add scoring to VR training activities. You’ll configure step-level scoring withStepScoringAuxiliary, aggregate scores at the activity level with ActivityScoring, and choose appropriate scoring types for different training objectives. This enables performance tracking, session posting, and real-time score feedback during VR training scenarios.
Prerequisites
- SDK modules: Molca Core, Molca VR SDK installed
- Unity setup: RuntimeManager configured, VR scenario set up with ScenarioManager and activities
- Prior knowledge: SequenceController, Step, ScenarioActivity
- Recommended: Complete Recipe: Set up a VR scenario first
Step-by-step
Step 1: Add StepScoringAuxiliary to steps
AddStepScoringAuxiliary components to individual steps that should contribute to the activity score.
StepScoringAuxiliary is a step auxiliary that hooks into the step lifecycle (OnStepBegin, OnStepUpdate, OnStepCompleted). It automatically tracks elapsed time, calculates scores based on the configured ScoringConfig, and optionally posts results to the session backend.
Step 2: Configure step scoring type
Choose aScoringType that matches your training objective for each step.
ScoringType implements a different scoring formula in ScoringConfig.CalculateScore(). Time-based types (TimeBonus, TimePenalty, Countdown) refresh every frame during OnStepUpdate, while static types (PointValue, Binary) calculate once on completion. The scoreMultiplier field scales all results, and allowNegativeScore controls clamping.
Step 3: Set accuracy for Binary and Accuracy scoring
For steps that validate correctness, callSetCorrect(), SetIncorrect(), or SetAccuracy() before the step completes.
StepScoringAuxiliary defaults to accuracyValue = 1.0 (full credit). For Binary scoring, accuracy >= 0.5 awards correctPoints, otherwise incorrectPoints. For Accuracy scoring, the value lerps between minPoints and maxPoints. Calling these methods before Complete() ensures the accuracy is set before FinalizeScore() runs.
Step 4: Add ActivityScoring component
Add anActivityScoring component to the activity root GameObject to aggregate step scores.
ActivityScoring is marked [RequireComponent(typeof(ScenarioActivity))] and automatically collects all StepScoringAuxiliary components from the activity’s SequenceController.Steps on OnActivityStarted. It combines them using the selected ScoreAggregationMode and adds any base activity score from activityScoringConfig.
Step 5: Configure activity-level scoring (optional)
Add a base activity score that applies regardless of step performance.ScoringConfig can contribute a base score independent of step scores. This is useful for rewarding overall activity completion speed or providing a fixed bonus. The activity score updates during Update() if the activity is active and the config is time-based.
Step 6: Subscribe to score events for UI updates
Listen toOnScoreChanged and OnScoreFinalized events to update UI displays.
OnScoreChanged fires whenever any step score updates (including time-based scores that refresh every frame). OnScoreFinalized fires once when the activity completes. GetMaxPossibleScore() returns the theoretical maximum based on all step and activity scoring configs, useful for percentage calculations.
Step 7: Enable session posting (optional)
Configure step scoring to post results to the backend session system.StepScoringAuxiliary.PostStepScoreAsync() runs after FinalizeScore() if postScoreToSession is true. It resolves the ScenarioSessionManager, ScenarioActivity, and org IDs from the scenario data config, then posts the score, elapsed time, and accuracy to the backend. This enables persistent progress tracking and analytics.
Complete example
Here’s a complete fire extinguisher training activity with multi-step scoring:- Multiple scoring types across different steps
- Activity-level time bonus on top of step scores
- Custom step logic that sets accuracy based on performance
- Real-time score updates during fire extinguishing
- Total possible score: 10 + 50 + 30 + 100 + 50 = 240 points (if all maximums achieved)
Troubleshooting
- Step scores always zero: Check that
ScoringTypeis not set toNone. For time-based scoring, verifytargetTimeSecondsandmaxTimeSecondsare configured correctly. ForBinaryscoring, ensureSetCorrect()orSetIncorrect()is called before the step completes. - Activity score missing step contributions: Verify
Include Step Scoresis checked onActivityScoring. Ensure steps are registered in the activity’sSequenceController.Stepsarray. Check thatStepScoringAuxiliarycomponents are attached to step GameObjects. - Session posting fails: Confirm
ScenarioSessionManageris active and a session is created. VerifyOrgScenarioId,org_activity_id, andorg_step_idare set in scenario data. Check thatpostScoreToSessionis enabled onStepScoringAuxiliary. Review console logs for specific error messages. - Time-based scores don’t update: Only
TimeBonus,TimePenalty, andCountdowntypes refresh duringOnStepUpdate. Ensure the step is active andUpdate()is running. For activity-level time scoring, verify the activity is active (IsActive()returns true). - Binary scoring feels inverted:
Binaryscoring awardscorrectPointswhen accuracy >= 0.5. UseSetCorrect()(sets accuracy to 1.0) for correct actions andSetIncorrect()(sets accuracy to 0.0) for incorrect actions. Don’t manually set accuracy values between 0 and 1 for binary scoring. - Negative scores appearing: Set
allowNegativeScoreto false inScoringConfigto clamp final scores to >= 0. Alternatively, adjustminPointsor reducepointsPerSecondforTimePenaltyscoring to prevent negative results. - Max possible score calculation wrong:
GetMaxPossibleScore()sums the maximum from each step’sScoringConfigplus the activity’s base config. It does not include runtime manual offsets fromAddBonusPoints(). Verify each step’s scoring config has correctmaxPointsorbasePointsvalues.
Related
- Scoring Config — scoring types, formulas, and configuration reference
- Step Scoring Auxiliary — step-level scoring API and session posting
- Activity Scoring — activity-level score aggregation and events
- Recipe: Set up a VR scenario — prerequisite VR scenario setup
- ScenarioActivity — activity lifecycle and integration
- Step — step lifecycle and auxiliary system
- VR step auxiliaries — overview of auxiliary components