Editor: Launch the editor with a headset connected and you should see this toggle inside the editor. Flip it on to enable VR.
nGame: When launching the game, pick "Play s&box VR in OpenXR Mode" to enable VR.
An example setup is available on sbox-scenestaging under the "test.vr" scene.
Here's a basic explanation of the different parts you'll come across:
The anchor represents the center of the player's playspace.
If you want your player to be able to move around, add the "VR Anchor" component to the same GameObject that you're using for your player. This will move the virtual playspace along with it.
The Target Eye represents the eye(s) that the camera can render to. A basic VR setup should have both Left and Right eye targets in order to display properly inside the headset.
A basic VR setup should also have a VR Tracked Object component on the camera, set up with the Head pose source, in order for the camera to follow the player's head movements.
On any object you want to track the player's controllers, add a VR Tracked Component for the object you want to track.
For example, this component will make the GameObject it's attached to follow the player's left controller:
Here's a basic overview of the VR C# API:
Get controller values
// Get left hand controller grip
var grip = Input.VR.LeftHand.Grip.Value;
// Check if the player is pulling the trigger a bit
if ( Input.VR.LeftHand.Trigger.Value > 0.5f )
{
Log.Trace( "Shoot!" );
// Vibrate the controller
Input.VR.LeftHand.TriggerHapticVibration( duration: 0.5f, frequency: 10, amplitude: 1.0f );
}
if ( Game.IsRunningInVR )
{
Log.Info( "I am running the game in VR!" );
}