SteamVR Unity plugin hands on

First impressions on SteamVR Unity Plugin from an Oculus Rift developer

As an Oculus developer since 2014 (ah, the good old DK2 times), I’ve always developed using Oculus Plugin inside Unity. I know it quite well and in fact, I’ve also made a tutorial about how to use your Avatar SDK inside Unity. Sometimes I also gave a look to other plugins, especially for developing the various portings for our ImmotionRoom system for all the available headsets, but I can’t say I’m very good with them. So these days I started giving a thorough look at SteamVR plugin.

SteamVR is very cool because with it, you can develop applications for both the Rift and the Vive, so knowing how to use it is important. That’s why I’m studying it… it can be useful also for my upcoming project. Oculus plugin on its side has the advantage that it can make you develop for both the Rift and the Gear VR, so for both PC and mobile platform… and we all know that mobile VR market is at least 10x the PC one, so this is very compelling. But this means practically designing two different applications since mobile developing has its peculiarities: requires a low poly number and interaction has to be performed with gaze or with a remote. On a PC you can have a good number of polygons and you have ergonomic controllers like Oculus Touch or the upcoming Vive Knuckles… so GearVR and Oculus Rift versions of the same application are quite different. Developing with SteamVR, instead, since we’re talking only about PC headsets, you have just to think about the best controller buttons to be used for each headset and not without touching anything else, you’re deploying for multiple platforms.

So, I went to Unity Asset Store and imported the SteamVR Plugin into an empty Unity solution. After all the import, the annoying SteamVR window asking to set properties of Unity project to recommended ones popped out. This is the thing that I hate the most of Valve’s plugin. This f**king window is like Terminator for John Connor in the first movie of the saga: it is there to ruin your life and it is indestructible. I accepted all the recommended settings, but don’t know for which reason, I couldn’t modify the “Show Unity Splashscreen”: I said “accept”, but it couldn’t change the setting, so every time I hit play, this windows popped up and it was a nuisance. In the end, the solution has been selecting “Ignore all”, so it died as Terminator under the hydraulic press.

SteamVR Unity plugin hands on
Damn window… I hate you. It also created problems for our automated build via script for ImmotionRoom

Ok, after having killed the robot… what should I do? The most [sarcarsm]amazing[/sarcasm] thing of Unity SteamVR plugin is that it is not documented. “It is open source, so you have to understand it by yourself” seems the vision of its developers. “I have a life and I have more interesting things to do” is my answer, but they are not much concerned. I’m not kidding, the only official documentation that you can find is:

  • A little quickstart guide PDF
  • A little documentation on the interactions engine in PDF
  • Code comments
  • Native OpenVR official documentation that you may use to better understand the API calls wrapped by the Unity plugin

The quickstart guide is the first one that I opened. It can be summarized in “Take your main camera and add a SteamVR_Camera script to that object”.

doge steamvr docs
Such wow, lots of info, so cool.

But this is how I actually started. And I have to admit that it is pretty cool: you add that script to the main camera and magically you have your HMD tracked in VR through SteamVR, plus some objects to reference head and ears: that camera has become a VR camera. But after that… well, I was lost again. How about reading the code?

Looking at the code is hard. Code is well written but needs time to be understood. This is a plugin that has to support different kinds of devices, so it contains various level of abstractions. A lot of stuff gets generated/activated/deactivated at runtime, because only at runtime the system understands what devices are tracked by the system. This makes understanding the code more difficult. Comments help, but they’re not too many. I’m a heavy commenter: my programs are full of green lines (more than black ones!) because I always forget why I made some choices, so I have to write them. Unluckily, memory of Valve developers is good, so only the most crucial parts are commented. Sometimes comments contains gems like

// If someone knows how to keep these from getting cleaned up every time
// you exit play mode, let me know.

(LOL. Anyway no, I don’t know 🙂 ) but they can’t be considered a proper documentation, especially for newbies. What about the second PDF that I mentioned above?

The other PDF is in the folder InteractionSystem, that contains the interaction system for SteamVR. This is the coolest thing that SteamVR guys have made for us. They’re taking the code they’ve used for basics interaction of the player inside the famous game The Lab and they’re giving it to us for free! This is simply amazing. These facilities include:

  • A player controller
  • Teleportation mechanics
  • An interaction engine with some basic interactions and also a cool one like the bow and the arrow
  • Integration of controllers with Unity UI (so that you can use controllers to interact with UI elements)
  • Highlighting of controller parts for tutorials
  • Ability to test the VR application using just mouse and keyboard on flat screen, super-useful if someone in the team doesn’t have a VR system

These functionalities are fantastic: you’ve everything you need to move inside the VR world and interact with objects around you. Furthermore, the framework is customizable: if you want to add a new type of interactable objects, it is absolutely possible; if you want to change graphics of teleportation and not use the standard one, it is possible. This is a huge time saving for all VR developers. This alone makes the SteamVR plugin very very interesting… it is, in my opinion, its most precious part.

SteamVR Unity plugin hands on
The sample interaction scene: I’m firing a bow and I haven’t still written a single line of code!

To explain the functionalities of this interaction engine there is a sample scene and a decent documentation PDF. Documentation and sample scene are enough to get started with this interaction engine and create elements that you can grab and throw. But, again, to understand things further and be able to modify the standard behaviors, you have to take some time and read through the code of the sample and make some experiments toying around with various parameters and scripts. The Player prefab they give to you is enormous and composed of various components: some disabled, some enabled, some default, some customs… it is far from simple to be completely understood.

What I understood, in the end, is that if someone wants to use out of the box a lot of pre-existing tools, the best thing is starting directly with the Interaction Engine. If you’re new to the SteamVR world this is surely the best choice: you just add a Player prefab into the scene and have a lot of things out of the box: you can move, you can take objects, you can throw stuff, you can play archery games! If you’re experienced and want to create a custom interaction system, you can start from the [CameraRig] prefab and have all the VR system set up including controllers and Chaperone and build completely your application on top of it. If you want to have just a VR camera and make everything in a custom way, you can start by just adding the SteamVR_Camera script as suggested above.

SteamVR Unity plugin hands on
Toying around with the Interaction Scene… I sincerely advise you to start from this one

After this first hands-on with SteamVR, I’ve mixed opinions on it. On one side I find it very powerful and very well designed: it can support various devices, additional tracked objects (like Vive Trackers), etc… and its code is greatly architectured. On the other side, it is really poorly documented: plugin architecture is very complex and more documentation would surely help. I would really like to have a doc explaining the use of each prefab, the meaning of each script, how things get generated at runtime and this kind of info. With the Rift, I remember before approaching development, I had found an official doc of 50 pages telling me about all prefabs, all the scripts, and their relative parameters. This can be boring to be read, but also very useful to guide the developer in understanding the tools he/she’s using.

So my advice for beginners is finding some online tutorials (there are some) before starting developing with SteamVR. In the meantime, I’ll let you know about what my experience with this dev tool (subscribe to my newsletter to know more!)

(Header image by SteamVR)


Disclaimer: this blog contains advertisement and affiliate links to sustain itself. If you click on an affiliate link, I'll be very happy because I'll earn a small commission on your purchase. You can find my boring full disclosure here.

Releated

playstation vr 2

The XR Week Peek (2024.03.26): Sony halts production of PSVR 2, Meta slashes the price of Quest 2, and more!

This has been the week of GDC and of the NVIDIA GTC, so we have a bit more pieces of news than the usual because there have been some interesting things announced there. Oh yes, also IEEE VR had its show. Actually, a lot of things happened for tech people in the US, which is […]

We need camera access to unleash the full potential of Mixed Reality

These days I’m carrying on some experiments with XR and other technologies. I had some wonderful ideas of Mixed Reality applications I would like to prototype, but most of them are impossible to do in this moment because of a decision that almost all VR/MR headset manufacturers have taken: preventing developers from accessing camera data. […]