Notifications
Article
SteamVR 2.0 Starter/Migration & Action Sets
Updated 13 days ago
210
2
Learn the new workflow, save time, and support more devices
With the new release of the SteamVR 2.0 plugin for Unity, came with it a plethora of goodies for the codebase and ecosystem that allows for more expandability as VR moves forward. However, if your are a developer like me moving from 1.0 to 2.0, or just a new developer starting out, the new workflow can be a bit confusing but this tutorial should help you get your feet wet if you’re starting from scratch or updating your project to the latest workflow.

What’s new in 2.0?

  • Button Agnostic Input Binding Action Sets
  • Input Debugger
  • New Browser/Input Binding UI

Getting started

Start by installing SteamVR from Steam and opting into Beta Updates (Important and Required!)
If you've successfully installed SteamVR beta, it should look something like this:
Grab the latest version of the plugin from the asset store: https://assetstore.unity.com/packages/tools/integration/steamvr-plugin-32647
After importing it in your project, you may see this pop up:
If you don’t know what exactly everything means in this window, just press Accept All as any differentiation from the default could prompt this window to open up over and over again in the future. It’s a pop up window that keeps asking you to use the recommended SteamVR settings for the preferred experience.

Navigating the UI

You can poke around the folders and sample scenes provided by Valve but we’re going to cover how to set up custom actions sets and actions binding for your own project.
To get access to the list of default bindings navigate to Window > SteamVR Input
If you’re doing this for the first time, press the Save and generate button first to generate the boilerplate json action sets and action files for you.
Upon completion you will notice a few things that have been added into your Project window.
Notice that by default, three action sets will have been generated for you:
  • default
  • platformer
  • buggy
By default, the default action set will be selected. You have the option of building custom actions on top of this default action set, or creating and publishing a completely new action set.

The UI Binding Interface & The Input Live View Debugger

Before we get started, we will take a look at how these are all linked up in the new button mapping interface. Make sure SteamVR is open and Click the Open binding UI button and it should fire up in your browser. Try using Chrome as it has been reported to not work as expected in other browsers.
You should start in a screen that looks like this:
Be sure to power on your SteamVR controllers (Vive Controllers, Trackers, Knuckles, etc.) or else they will not show up as a mapping option.
After powering up, select your desired controller and click the Edit button and you can see here the relative actions in the action set and their corresponding default bindings.
If you go back to Unity and Open Window > SteamVR Live Input View, you will also see the action sets and their states. Drop an instance of the [CamraRig] prefab in your scene and you can see how button presses are firing off different actions in the default action set.
Remember you need to be in Play Mode to see these action changes.
Likewise, you can also activate this inside the UI Binding interface in Chrome by clicking the Input Debugger button to see the actions being fired.

Creating Your Own Custom Action Set

We begin by returning to the SteamVR Input window in Unity and pressing the + button.
Name your new action set and create some actions.
Note that depending on what your action is you will need to define its type. Ie. If you’re using responds for a direction pad or trackpad, you need to set it up as a vector2. If you’re setting up a button you need to choose boolean as your variable type.
Also important, be sure to add a Pose action or else the plugin may not work with the newly created action set
When you’re done, press save and generate and let Unity do its thing. This may take a while, but Unity is building relevant ScriptableObjects for each action set/action and putting them into your SteamVR_Input folder.
Once it’s done, we need to link things up in the bindings UI. If you go back to the bindings UI interface, our new action set should show up on the right. (You also do this step inside VR if you're feelin' fancy)
Navigate over to the tab and press the + button. Link up all the actions to their desired buttons. Note that if you mouse over the tab, any unbound actions will be shown in the tooltip as being listed in the number beside the tab. Any action sets with non fully mapped actions will show up as red.
Because each button can be treated as different states for input entry, you will be prompted with this popup when you try to add an action to any button.
Select the one that corresponds to your usage. In our example will be binding ShootProjectile to the trigger as a Button action.
Note that our previously created actions have all be turned into lowercase slugs. This is normal, so just select the action that corresponds to your button.
When complete it should look something like this.
Lastly, we will bind the pose. Click the Add Action Pose button.
Under Left Hand Raw we will attach the pose action to it. Note that if you didn't initially set the Pose action to type pose in the SteamVR Input window, it won't show up on binding UI. The same can be said for the types of all the other buttons, so be sure to assign the proper types to each button.
In this example we will be using the same buttons for both left and right hand. So as long as Mirror Mode is checked we're good.
The rationale behind this is that actions and button presses can be agnostic. This means you can remap the actions to different buttons of the same type without changing a line of code. But we’ll get to how to set this up later.
When you’re done linking up the actions, press Save Personal Binding to save your profile and press Replace Default Binding to replace the default binding for this application and to have the action set accessible inside Unity.

The Code

We’ll start by creating a new script and populating it with the following:
using System.Collections; using System.Collections.Generic; using UnityEngine; using Valve.VR; public class DemoActionSetInput : MonoBehaviour { public SteamVR_ActionSet actionSetEnable; public SteamVR_Action_Boolean shootProjectile; public SteamVR_Action_Boolean reloadProjectile; public SteamVR_Action_Boolean cycleItems; public SteamVR_Action_Vector2 menuSelect; void Start() { actionSetEnable.ActivateSecondary(true); } void Update() { if (shootProjectile.GetState(SteamVR_Input_Sources.Any)){ Debug.Log("PEW PEW"); } if (reloadProjectile.GetState(SteamVR_Input_Sources.Any)){ Debug.Log("RELOAD"); } if (cycleItems.GetState(SteamVR_Input_Sources.Any)) { Debug.Log("NEXT ITEM"); } Vector2 menuPosition = menuSelect.GetAxis(SteamVR_Input_Sources.Any); } }
Since this is just a basic example, we will just be printing to the console.
It’s important to note that the most important part here is the ActivateSecondary() function call in the Start() function. Without it, the newly created action set will not fire in the SteamVR Input Live View nor anywhere else.
After you’ve created the new script, attach it to your [CameraRig] or any other GameObject. Select the relevant actions and action sets in the inspector and we can see our new action set at work inside the SteamVR Input Live View. Enter Play Mode and note that with the ActivateSecondary() call, the default action set becomes Inactive and the new action set becomes Active.
And we're done!

Conclusions

The rationale behind this new input system is that as programmers, you only need to define all the actions related to your game once. With any new controllers that come out in the future, you don’t need to re-code your game to support every single type of controller in the ecosystem. You should be able to take any given controller, and remap the existing action set actions to the new controller and play the game just fine.

References

  • Asset Store Download - https://assetstore.unity.com/packages/tools/integration/steamvr-plugin-32647
  • GitHub - https://github.com/ValveSoftware/steamvr_unity_plugin
  • Steam Community Tutorial - https://steamcommunity.com/sharedfiles/filedetails/?id=1416820276
  • Moondust Demo - https://github.com/ValveSoftware/Moondust
Need extra help with SteamVR 2.0 or your XR project? Contact a live expert today!

Warren Wang
CEO - Programmer
12
Comments
Штумоз™
11 days ago
уникальная торговая марка Штумоз™ -Shtumoz™ - Other
зачем делать то -что вы не сможете продать? кто это купить? вы бы в это сами играли?
0
Штумоз™
11 days ago
уникальная торговая марка Штумоз™ -Shtumoz™ - Other
графика на уровне 3 по 5 ти бальной, чем ваша игра отличается от точно таких же игр и бесплатных?
0