SteamVR Unity Plugin

repository·master·Indexed 22 days ago

https://github.com/valvesoftware/steamvr_unity_plugin

A unified interface for integrating SteamVR into Unity applications, supporting Unity versions 5.4 through 2019.1. The plugin manages 3D controller models, input handling, and hand estimation. It includes components such as SteamVR_Camera for VR support, SteamVR_Overlay for 2D content, and SteamVR_TrackedObject for device tracking. It provides an Interaction System for object picking and throwing, and a system for handling SteamVR events like device connection and calibration.

Tokens
2K
Snippets
2
Records
14
Agent score
28%

What's inside SteamVR Unity Plugin

  1. Explore SteamVR Unity Plugin sample scenes

    master

    The plugin includes several sample scenes to demonstrate different levels of complexity:

    • Simple VR with Tracked Controllers: For a minimal implementation, open the scene located at /SteamVR/Simple Sample.
    • Interaction System Example: For a comprehensive implementation including object picking, throwing, and animated hands, open the scene at /SteamVR/Interaction System/Samples/Interactions_Example.
  2. Set up input actions for the Interaction System

    master

    If you are exploring the Interaction System example, you must generate the necessary input actions manually:

    1. Open the SteamVR Input window via the Unity Window menu.
    2. When prompted, click Yes to copy the example JSON files.
    3. Click Save and Generate to create the required input actions.
  3. Requirements for SteamVR Unity Plugin

    master

    To use the SteamVR Unity Plugin, ensure the following requirements are met:

    1. SteamVR Runtime: Must be installed on the system. It can be found in the Steam 'Tools' category or via the Steam Store.
    2. SteamVR Beta: It is strongly recommended to opt-in to the SteamVR beta to test new features and ensure compatibility with the latest SteamVR versions.
    3. Unity Version: This version of the plugin is compatible and tested with Unity versions 5.4 through 2019.1.
  4. Configure SteamVR Input for Steam Publishing

    master

    If you publish your game on Steam, you can allow users to change input bindings outside of the game by designating your title as a SteamVR Input application.

    Steps to configure on Steamworks:

    1. Go to the Steamworks Partner Site.
    2. Navigate to Application settings -> Virtual Reality Section.
    3. Select the radio button to designate your title as a SteamVR Input application.
    4. Set the location of your action manifest.

    Manifest Location:

    • For plugin versions 2.3.3 and above, the manifest must be located at: [GameName]_Data/StreamingAssets/SteamVR/actions.json
  5. Quick Start: Setting up SteamVR Input

    master

    To use the SteamVR Input system and explore interaction scenes, you must generate the necessary input action files:

    1. Open the SteamVR Input window (found under the Window menu in Unity).
    2. If prompted, click yes to copy the example JSON files.
    3. Click Save and Generate to create the required input actions.

    For learning purposes, you can explore these sample scenes included in the plugin:

    • Simple VR Example: SteamVR/Simple Sample (Basic tracked controller interaction).
    • Interaction System Example: SteamVR/Interaction System/Samples/Interactions_Example (Advanced features like picking up, throwing objects, and animated hands).
  6. Troubleshoot SteamVR connection and initialization errors

    master

    Common errors and their solutions:

    ErrorSolution
    Failed to connect to vrserverOften happens on first launch; try launching a second time.
    HmdError_Init_VRClientDLLNotFoundEnsure SteamVR runtime is installed via Steam Tools. Try deleting <user>/AppData/Local/OpenVR/openvrpaths.vrpath and relaunching Steam.
    HmdError_Init_HmdNotFoundCheck USB connections. If persistent, try deleting Steam/config/steamvr.cfg.
    HmdError_Init_InterfaceNotFoundUpdate your SteamVR runtime.
    HmdError_IPC_ConnectFailedCommunication pipe closed. Check Task Manager for rogue vrserver.exe processes. Often caused by long load times; try launching a second time.
    Not using DXGI 1.1Set the environment variable ForceDXGICreateFactory1 = 1 and launch the app via Steam.
  7. Render 2D content in VR with SteamVR_Overlay

    master

    The SteamVR_Overlay.cs component is used to render 2D content (like UI) on a virtual curved surface in VR.

    Usage

    • Drag the component into the Hierarchy window (rather than the Scene window) to ensure it retains its default position at the origin.
    • To use it for specific scenes, add the component to those scenes and set its Texture property to None in scenes where you do not want it rendered.
  8. Configure SteamVR_Camera for VR support

    master

    The SteamVR_Camera.cs script adds VR support to an existing Unity camera object.

    Key Properties

    • head: The Transform representing the head position.
    • origin: The Transform representing the tracking origin.
    • sceneResolutionScale: Controls the resolution of the off-screen render target used to combat distortion. Higher values improve multisampling but increase cost.

    Setup

    To automatically create the necessary eye objects, press the Expand button in the SteamVR_Camera Inspector. To revert, press Collapse.

    Important Notes

    • Scaling: Scaling the SteamVR_Camera GameObject will inversely scale the world. For building at real-world scale, keep this at 1,1,1. If you have expanded the camera, scale the origin Transform instead.
    • Compatibility: GUILayer and FlareLayer are incompatible with SteamVR_Camera because they render in screen space. They are automatically moved to the SteamVR_GameView object (a child of the head).
    • Audio: The AudioListener is automatically transferred to the head to ensure proper spatialization.
  9. Listen to SteamVR events

    master

    SteamVR broadcasts several events that can be handled by registering via SteamVR_Events.<EventType>.Listen.

    Best Practice: Always call Remove in OnDisable to avoid memory leaks or errors when components are destroyed.

    Available Events

    • Initializing: Sent when the HMD's tracking status changes to or from Uninitialized.
    • Calibrating: Sent when starting or stopping calibration.
    • OutOfRange: Sent when losing or reacquiring absolute positional tracking.
    • DeviceConnected: Sent when devices are connected or disconnected. Arguments: int deviceIndex, bool connectedStatus.
    void OnEnable() {
        SteamVR_Events.DeviceConnected.Listen(OnDeviceConnected);
    }
    
    void OnDisable() {
        SteamVR_Events.DeviceConnected.Remove(OnDeviceConnected);
    }
    
    void OnDeviceConnected(int index, bool connected) {
        // Handle connection
    }