How To Use SteamVR (2.0) Input In Unity

Not much need to be said about the new input system steam has implemented. People hate it, I like it, people hate me. I hope I’m kidding about that, we’ll see when this article goes live. But the reason I like it is probably that I understand it, and from what I can tell that is a rare thing. Thus this article. I really hope you like it and find it useful, If you have any questions post them in the comments section. Now that we have all that out of the way let’s get started.

Why Use Actions?

As you probably know, the new SteamVR input system is based on actions. Now, instead of directly accessing the inputs through code we have to assign variables to input sources through a custom gui. For us coders It may seem more complicated but there are advantages. One of the main goals of the action system is to allow your players to remap the controls of your game to their liking. That may sound scary but it’s what PC players have been doing for years with their mouse and keyboard. It only makes sense to let VR gamers do it to. Another benefit is that it allows you to map several different controllers to the same inputs without changing any of your code along with making last minute changes super easy.

How Does It Work?

All right, now for the grand tour. Open a unity project with the SteamVR plugin and go to the windows menu, you should see a button to open the SteamVR Input menu that looks just like this:

You are going to use the first Input panel the most but you ming also notice the button to open the SteamVR Input Live View, This is just a handy tool that shows you the current state of all your actions while in play mode. Go ahead And open the first input panel, It should look a little something like this:


(You won’t have the same inputs as me because I’ve messed with and added some but that’s beside the point.)

So let’s analyze this menu from the top down. For now we are going to ignore the Advanced settings button. Moving on we see a bunch of buttons in a line, these are how we switch between the different action sets, I’ll talk more about those in the GUI section. Next we see a dropdown that allows us to choose if our action set is mirrored or not, just keep it in mind for the gui section. Now we see the list of our actions. It’s important to name these well since your players can see them. I’ll teach how to make one in the section below. Next we see a list of haptics. maybe Important for you, but I haven’t used them yet. They are how we control the vibration of the controllers. Then we see two buttons: Save and Generate and Open Binding UI. The Save button speaks for itself but the UI button might be the most important one. When you click it it takes you to the binding ui where you “bind” actions to the controllers. Just not that you need to have steamVR open and your controllers on and connected for the UI to work.

Making An Action Input

To make an action just click the plus button at the bottom of the action list and you should get one like this:

Going once more from top to bottom we first see a field to enter a name. Once again I have to stress, make it intelligent sounding, people see it. Next we see the type drop down. This is where we choose what type of variable it is, there are 6 types:

Boolean’s are mostly used for buttons. On second thought, there only use i as a button.

Vector1, Basically a float. You can use it to get analog input from triggers and the like.

Vector2’s are used to get input from touchpads and thumbsticks.

vector3’s are a mystery, since the next type is used for positions. I guess Valve just wanted to cover all their bases.

poses are what are used now to get the position of the controllers and headset, under the logic that some people might want to change the point their controllers are tracked from.

skeleton’s are not yet implemented to Windows Mixed Reality Headsets so my knowledge about them is limited. Nevertheless, they are used to approximate the position of a users hand and display a corresponding model.

Next we have the Required bullet point list, this is used to tell your players the priority of a particular input. Just not that the binding UI will not let you save until all actions marked required are parred. The last two fields are outside the scope of this tutorial.

Using The UI

Now click the Open Binding UI button and you should get a screen like this:

This is where you select your controller and what bindings to change. You can select your controller by clicking the name of the current one and then selecting the correct one from the popup. To edit, click edit and the binding screen will open:

As always, we start at the top and work our way down. At the top of the page, we see four tabs, these match up with the action sets we see in the Input window. the idea is that you have different action sets for different situations. But it’s perfectly fine to only use the default one for now. On the left, we have a scrollable menu that allows us to assign actions to our controls. This is where most of the work is done, and where some of the confusion. comes in. It isn’t quite as simple as assigning an action to the trigger. First what you do is click the plus box next to the name of the control you want to use. This will bring up a menu asking what you want to use the control as. There are too many different examples to explain them all so it’s important to explore them yourself. Once you choose one, let’s say you are using the trigger as a button, you now see a new section on the left sidebar.

Now we can finally assign our actions. In the “use as” section that we just created you can see different events that trigger the actions assigned to them. To assign an action, just click the none box right next to the event you want to trigger your action and you will get a menu that shows you all the compatible actions you can assign to that particular event.

You may also notice that there is an identical menu to the right of the screen that is greyed out, this is because the action set is currently mirrored. You could change this in the Input window or with the checkbox in the middle of the screen but It’s a lot faster to just use mirrored action sets.

In the middle of the screen you see three buttons: add chords, edit action poses, and edit haptics. Chords are too complicated for this tutorial but action poses are really important. They are how unity gets the position and rotation of the controllers. As long as you don’t mess with the default bindings you shouldn’t have to worry about it. And Haptics is how you bind Haptic outputs to your controllers.

And finally, we have the five buttons at the bottom of the screen. The first, publish to workshop, is for your players. It allows them to publish their personal custom bindings to all the other players to use. The second, Save Personal Binding does what it says it does. Third, we have Show Developer Output, this allows you to see the raw JSON output of the binding UI. The fourth button, Save Default Bindings, is the most important. Clicking this button allows you to set the default bindings for the game, ie the one that players use when they first boot up the game. And finally, Input Debugger allows you to see the raw output of your controllers.

Using Action Input In Code

I feel that this 600-word long monolog is a little too long so I’m going to refer you to my VR hand tutorial, It has instructions on how to use input and some code you can copy directly into your project. I hope you found something useful in this article, If you didn’t, post a comment and I’ll try to fix it. I hope to see you around.

Liked it? Take a second to support WireWhiz on Patreon!
Become a patron at Patreon!

2 comments

  1. Hello, I am busy trying to figure out your last post about walking in VR,I followed the steps you gave and also read the comments.It sure did help a lot, if I when I hit play , what should i use to move?
    I tried holding the touchpad and by even double tapping , but there were still no movement.
    I tried out this post and still could not fix this problem.

    1. Without more information on your problem, I can’t be much help. When you touch the touchpad anywhere but the center you should move. Check to make sure you steamVR actions are set and make sure speed is not set to 0, It’s gotten me before. Also If you set the deadline to more then .9 you might have problems.

Comments are closed.