MolcaSDK.VRFile:
Assets/_MolcaSDK/_VR/Scripts/VRPlayerManager.cs
Attach to the XR Origin (XR Rig) root. Uses a static Instance; resolves VRSubsystem after RuntimeManager initialization.
When to use
UseVRPlayerManager when you need a single place to:
- Read player ground position (
GetGroundPosition— head XZ with XR Origin Y). - Enable or disable all XR Interaction Toolkit locomotion providers together (teleport, move, snap turn, etc.), e.g. during precision Grab step work.
- Access left/right
VRControllerVisualfrom static properties for haptics or visuals.
Inspector setup
| Field | Purpose |
|---|---|
| XROrigin | XR rig; required for ground position. |
| Player head | Camera / head transform for ground projection and locomotion logic. |
| Left / right controller visual | Optional VRControllerVisual references. |
| Auto discover locomotion providers | When on, finds all LocomotionProvider under this object (including inactive). |
| Manual locomotion providers | Used when auto-discover is off; assign the providers to toggle. |
WaitForInitialization, the manager caches providers and sets IsLocomotionEnabled from the first provider’s enabled state (or false if none).
Code
Disable locomotion for a precision step, then restore:EventConstants.VR.LocomotionStateChanged via EventDispatcher if other systems need to react (payload type LocomotionStateChangedData, property IsEnabled).
API (key members)
| Member | Description |
|---|---|
Instance | Singleton set in Awake. |
LeftControllerVisual, RightControllerVisual | Static; null if no instance. |
GetGroundPosition() | Static; returns Vector3.zero if no instance. |
IsLocomotionEnabled | Static; current locomotion flag. |
SetLocomotionEnabled(bool) | Enables/disables all cached providers; dispatches locomotion event. |
ToggleLocomotion() | Toggles locomotion. |
RefreshLocomotionProviders() | Re-runs discovery or manual list (Context Menu). |
GetVRSubsystem() | Returns resolved VRSubsystem. |
Troubleshooting
- “Instance not found” / null static access — Only one
VRPlayerManagershould exist on the active rig;AwakeassignsInstance. Ensure the rig is active before calling static helpers from arbitrary objects. - Locomotion toggle does nothing — Confirm
LocomotionProvidercomponents live under the same GameObject hierarchy (auto-discover) or are assigned in manual list. Check the Console for “No locomotion providers” warnings. VRSubsystem not found— RuntimeManager prefab must includeVRSubsystem; wait until after subsystem init (manager waits inStart).- Wrong ground height —
GetGroundPositionusesxROrigin.transform.position.y; verify XROrigin reference and floor / tracking setup.
Related
- Scenario activity — broader scenario / VR flow
- RuntimeManager — initialization and
GetSubsystem - Grab step — typical reason to disable locomotion
- EventDispatcher — locomotion state events
Unity Editor
XR Origin root with VRPlayerManager + locomotion components.
