menu_bookDocumentation

VR Development

calendar_today May 3, 2026 schedule ~2 min read person patrickjr verified 50

VR Development

Build virtual reality experiences with OpenXR support, tracked devices, and VR-specific components.

Setup

Enable VR in your project settings. s&box uses OpenXR for cross-platform VR support.

VR Components

VR Anchor

Locks the player's playspace to a GameObject's transform. Use this for:
  • Seated experiences (anchor to a chair/seat)
  • Room-scale movement (attach to player pawn)
  • Vehicle VR (anchor to car/plane cockpit)

VR Tracked Object

Moves a GameObject to match a tracked device:
  • Head — Camera position/rotation
  • Left Hand — Left controller
  • Right Hand — Right controller
  • Other devices — Trackers, base stations

VR Hand

Matches animgraph hand poses with SteamVR skeletal input for realistic finger tracking.

Basic VR Setup

CSHARP
public class VRPlayer : Component
{
    // Anchor locks playspace to this object
    [RequireComponent]
    public VrAnchor Anchor { get; set; }
    
    void Setup()
    {
        // Camera tracks head
        var camera = Components.Get<CameraComponent>();
        var headTracker = camera.GameObject.Components.Create<VrTrackedObject>();
        headTracker.PoseSource = VrTrackedObject.PoseSources.Head;
        
        // Hand controllers
        var leftHand = new GameObject();
        leftHand.Name = "Left Hand";
        var leftTracker = leftHand.Components.Create<VrTrackedObject>();
        leftTracker.PoseSource = VrTrackedObject.PoseSources.LeftHand;
        
        // Add hand component for finger tracking
        var leftVrHand = leftHand.Components.Create<VrHand>();
        leftVrHand.HandSource = VrHand.HandSources.Left;
    }
}

Input API

Access VR-specific input:

CSHARP
// Check if running in VR
if (Input.VR.IsActive)
{
    // VR-specific logic
}

// Controller input
var leftJoystick = Input.VR.LeftHand.Joystick;
var rightTrigger = Input.VR.RightHand.Trigger;

// Haptics (vibration)
Input.VR.LeftHand.Haptics.Vibrate(0.5f, 0.2f); // strength, duration

Rendering

VR renders in stereo with automatic optimization:

  • Single-pass stereo rendering

  • Foveated rendering support (if available)

  • Dynamic resolution scaling

Camera Configuration

CSHARP
// In VR, camera tracks head automatically
var camera = Components.Get<CameraComponent>();
camera.IsMain = true;

// Optional: Override FOV (usually let OpenXR handle this)
camera.FieldOfView = 90; // degrees

Comfort and Safety

Best practices for VR content:

  • Teleport movement over smooth locomotion

  • Snap turning over smooth rotation

  • Comfort vignette during fast motion

  • Seated option for all experiences

  • Height calibration on start

Platform Support

HeadsetSupport
SteamVRFull
Oculus/MetaFull (via OpenXR)
Windows Mixed RealityFull (via OpenXR)

System Requirements

VR requires:

  • Windows 10/11 64-bit

  • OpenXR compatible headset

  • VR-ready GPU (RTX 2060 / RX 6600XT recommended)

  • 16GB RAM recommended

Was this helpful?