construct and run OpenXR functions in Unity

After a very long time with my beautiful Unity 2019.4 LTS, I’ve determined it was time to change to one thing new, to not miss the brand new options that Unity has applied these years. I’ve so began utilizing Unity 2021.3 LTS (2021.3.5 to be actual) and experimenting with it. One of many new options supplied by the brand new Unity is the power of constructing OpenXR functions, and I wished completely to check it! Let me let you know what I found on this course of, specifically, learn how to construct utilizing OpenXR, and learn how to run the OpenXR functions in your PC.

This tutorial additionally is available in video format. If you would like, as an alternative of studying a wall of textual content, you’ll be able to see it within the video right here under:

I do know you missed my video tutorials, that’s why I’ve made a brand new one!


A really brief primer about OpenXR, in case you forgot what it’s: it’s a commonplace, created by the Khronos Group, which has been adopted by all the most important XR corporations and that permits for interoperability of XR {hardware} and software program from completely different distributors. That’s, an software constructed for the Oculus runtime also can run for the Valve Index on SteamVR. That is one thing wonderful, as a result of it lets us builders construct an software as soon as after which deploy it all over the place.

construct an OpenXR software

Let’s see learn how to construct a Unity 2021 software with OpenXR. Discover that on this written tutorial I assume you might be already assured with Unity. If you’re a newbie, please watch the above video the place you’ll be able to see me doing all of the steps in entrance of your eyes.

Venture preparation

Let’s construct an software utilizing OpenXR. As an alternative of creating the applying ourselves, I’m going to allow you to obtain an already-prepared pattern software, so we are able to skip all of the creation course of and have out of the field an app that lets us take a look at each the headset and the controllers interactions. I’m speaking in regards to the XR Interplay Toolkit Instance app, which you’ll be able to obtain from GitHub (hyperlink).

Obtain the supply code, after which open the undertaking that’s in its “VR” listing. It’s a Unity 2019.4 undertaking, however please drive Unity Hub to open it with Unity 2021.3. Unity will present you varied dialog home windows asking you a lot confirmations about if you’re certain you wish to convert to the next model of Unity, you wish to convert the database, the supplies, and many others… You at all times reply that sure, you might be certain. We gained’t come again…

Go Away Reaction GIF by MOODMAN - Find & Share on GIPHY

Browse some memes till Unity has completed all of the importing course of. After that, open the scene WorldInteractionDemo from the listing Belongings/Scenes/. It’s a pattern demo of the XR Interplay Toolkit with varied interactions with the setting. It makes use of the brand new Unity Enter System and all of the enter is wired via actions. This can be a element I’m specifying as a result of I’ve observed that Motion-based XR-origins match higher with OpenXR builds than System-based ones.

The scene is already working, so that you don’t have to switch something. Additionally the packages have already been up to date by Unity through the undertaking model improve, so that you don’t need to care about them in any respect. We will go on to the constructing section!

construct for OpenXR – PC

xr interaction toolkit sample unity
A view of the pattern software

Let’s see learn how to configure the undertaking in order that to construct for OpenXR. Open the construct window (File -> Construct Settings…) and add the present scene to the scenes to construct, if wanted. Then click on on “Participant Settings…” and within the undertaking settings, go to the XR Plugin Administration tab. Choose the “PC” platform in it (it’s the one with the small icon of a show) and see that there are numerous construct targets. Click on on OpenXR, and anticipate the appropriate plugin to load.

how to unity pc build openxr
configure the undertaking for OpenXR within the Venture Settings

After that, you will note that there’s an error, as a result of you need to configure the profile for it. Go on the OpenXR subtab and add within the “Interplay Profiles” part the profile of the controllers you might be utilizing. Since I take advantage of Quest+Hyperlink, I’ve added Oculus Contact Controller Profile. For those who plan to construct for various headsets, right here you must add all of the controllers that you simply plan to assist. And that’s it! Now we are able to construct the applying and have the executable that we would like.

controllers support openxr
set the controllers to assist

In case you additionally import the Oculus Utilities plugin, you’ve gotten one other flag to examine, “OculusXR Function”, which helps you to enable the options contained within the Oculus Package deal to run even with OpenXR. I doesn’t counsel you to do that, although, as we’ll see shortly.

construct for OpenXR – Android

For those who swap the construct goal to Android, you must repeat for Android the identical issues carried out earlier than, that’s you must choose OpenXR because the XR plugin for the construct within the Android subtab and you must add the interplay profiles of the controllers you might be planning to make use of.

Discover that almost all most likely when constructing for a standalone headset (e.g. the Quest), you even have to alter different settings, like setting the colour area as Linear and setting the construct structure as ARM 64, however these are settings not associated to OpenXR, so I gained’t cowl them right here.

Issues to watch out about when constructing for OpenXR

Be Safe GIF by Saturday Night Live - Find & Share on GIPHY

Some ideas from my expertise:

  • Construct with OpenXR for PC, however not for standalone VR headsets. Quest assist for OpenXR remains to be not production-ready (as you’ll be able to see in this desk), and I had some builds not working correctly myself. Pico doesn’t assist OpenXR but, making you lose the benefit of deploying for “a number of platforms”. So, for Pico Neo and Quest, I nonetheless construct with the XR plugin associated to the vacation spot platform. I hope it will change sooner or later, however on the time of writing, issues are this fashion;
  • Use Motion-based XR Rigs when constructing for OpenXR. I’ve observed that System-based Rigs produce incorrect interplay rays orientation if you use OpenXR as runtime
  • Carry out testing in your undertaking: I’ve observed that there are nonetheless some general instabilities and incompatibilities when utilizing OpenXR with Unity. I nonetheless contemplate it a beta implementation;
  • Keep in mind that when utilizing OpenXR in Unity, in the meanwhile, you cannot use the functionalities of the distributors’ plugins in your tasks. Which means if you’re utilizing OpenXR to construct for Quest, you’ll be able to’t use the functionalities of the Oculus Utilities bundle. There’s a “OculusXR Function” flag within the OpenXR settings tab which is supposed precisely to permit that, however for those who activate it, the system doesn’t detect the place of the Oculus Contact controllers anymore (it is a bug with the Unity 2021 model, somebody means that reverting to Unity 2020 solves the problem). To make issues work once more, you must deactivate the flag, however then you’ve gotten an annoying dialog suggesting you to activate it each time you run in play mode. So, my suggestion is to not import the Oculus plugin from the Asset Retailer in any respect.

All in all, I believe that OpenXR has nonetheless a protracted highway to go to turn out to be adopted by all engines, headsets, and runtimes in a steady method.

Testing an OpenXR software in play mode

How are you going to take a look at your OpenXR software in play mode in Unity? Nicely… hitting the play button… as traditional.

However there’s one characteristic extra for PC… you’ll be able to select the runtime to check it on! Since OpenXR can work each with Oculus and SteamVR runtimes, you’ll be able to choose in a drop-down menu what sort of runtime you need your play take a look at to run on. This fashion, you’ll be able to confirm simply in case your recreation works on all platforms. The dropdown is within the XR Plugin Administration -> OpenXR subtab of the undertaking settings: it’s referred to as “Play Mode OpenXR Runtime”. Strive choosing completely different choices and hitting play and you’ll discover that the applying can be redirected to the appropriate runtime each time.

play mode unity openxr
change the OpenXR runtime for the play checks

Constructing and working an OpenXR software

That is simple peasy, too. You simply construct the applying within the traditional method, that’s hitting “Construct” button within the Construct Settings window and selecting the place would you like it to be constructed.

At this level, you’ve gotten an executable, you run it, and it (hopefully) works.

However now I’ve a query for you: how do you take a look at it with the completely different runtimes? I imply, earlier than OpenXR, you had completely different builds for various headsets, and your pc was sensible sufficient to grasp if open it with Oculus or SteamVR, however what about now that the executable file is just one? How do you select that you simply wish to run it via SteamVR, as an example? After all, I don’t have solely the query, but additionally the reply…

This level puzzled me loads, and I needed to ask the assistance of Saint Google to resolve it. As a result of I stored having the applying working with the Quest runtime even when I had SteamVR open and even when I opened it through Steam shortcuts. It seems that on the system degree, you’ve gotten just one lively OpenXR system, and you must select which one it’s. And no matter you run, will get executed by that runtime, which is hopefully your most well-liked one, that’s the one that you simply use essentially the most to your video games. For example, since I take advantage of Oculus Hyperlink loads, my default one was the Oculus one, and that’s why all my OpenXR builds have been executed via the Oculus runtime. When in Unity you choose “System Default” as your “Play Mode OpenXR Runtime”, that is precisely the one that’s utilized in play mode.

To vary your lively runtime, you must open the settings of your runtime and choose that you really want that as the popular system.

In Oculus, it means opening the Oculus software in your PC and going to Settings -> Normal, and clicking the button Set Oculus As Energetic on the OpenXR Runtime line.

how to openxr on oculus runtime
The steps to activate OpenXR within the Oculus runtime. Sorry for the Italian language

For Steam, initially, you need to have a headset linked, then you’ll be able to head into the Settings of Steam VR, activate the Superior Settings, select the “Developer” tab, and there you discover a button to set SteamVR because the lively OpenXR setting. After all, just one runtime may be lively on the similar time, so for those who activate Steam, you will deactivate Oculus, and all the subsequent occasions you’ll launch an OpenXR software, it will likely be launched via SteamVR.

how to openxr in steam vr
The steps to activate OpenXR within the Steam VR runtime. Sorry for the Italian language

This fashion, you’ll be able to play your construct with completely different runtimes. Isn’t it fascinating how a single EXE file may be run in numerous methods by completely different headsets and runtimes? For me it’s! It’s the magic of OpenXR…

I hope this tutorial has been helpful for you, and if it’s the case please subscribe to my publication and share this text with all of your fellow VR recreation builders!

(Header picture containing Unity brand and OpenXR brand by Khronos group)

Disclaimer: this weblog comprises commercial and affiliate hyperlinks to maintain itself. For those who click on on an affiliate hyperlink, I will be very glad as a result of I will earn a small fee in your buy. You could find my boring full disclosure right here.


Latest articles

Related articles

Leave a reply

Please enter your comment!
Please enter your name here