Getting Started with VR in Unity
VR (Virtual Reality) and XR (Extended Reality) entertainment and education, is a rapidly growing industry. From games and immersive video experiences, to medical and automotive training simulators, the world of VR appears here to stay. This series will explore getting up and running with VR using Unity and the Oculus Quest 2.
Setting up the Quest 2
If this is the first time using your device, you will be prompted to setup your language, controllers and boundary. You may also be prompted to update your software and read a safety notification.
Pairing with the Meta Horizons Application
In order to pair your headset, you need to download the Meta Horizons application for your mobile device. You will be asked to log-in to your account, and then select a device to pair. After the headset is found, the app will ask for a passcode that can be seen in the headset. If a pop-up doesn’t appear in your headset with the pairing code, you can find it by navigating to Settings > System > About > Pairing Code.
Taking Screen Shots in VR
As a side note, if you want to take screen shots in the Oculus headset, press and hold the Oculus button on your right controller, then pressing the right trigger will take a screen shot. You should hear a camera shutter sound as confirmation.
Oculus Software (Quest Link)
If you want to link your Oculus to your PC, you can do so with the Quest Link Software, but note that not all computers have a compatible video card.
Check the specs in the link below before downloading 9+ GB of Quest Link software.
If you computer is up to the task of using Quest Link, you can download it with the link below.
After installing the oculus software you will need to login with your email or Facebook account.
You should now have the option to connect by either Wi-Fi or a cable. While Wi-Fi is a convenient and cable free option, but will drain your battery. The cable on the other hand, will charge your headset while you work.
After selecting Link cable, if that is the option you are choosing, you can now plug the other end of the cable into your headset.
If desired, you can test your connection speed.
Inside the headset now, you should be able to Enable Quest Link.
Incompatible graphics card? What to do?
If your computer doesn’t have the needed hardware to run the Oculus with Quest Link, fear not! While it’s great to be able to test your application live in Unity with the Oculus Link software, there are some other options available for the hardware challenged.
XR Device Simulator
While it is clunky compared to the actual VR controllers, the XR Device Simulator can be used to have Keyboard controls drive simulated XR controllers and an XR head mounted display.
More information on setting up and using the XR Device Simulator can be found in the Unity documentation below.
Build for Android and Sideload to Oculus
SideQuest is a great option with a variety of installers for PC and Oculus to suit your needs. While you may not be able to do live play testing in Unity with the Oculus, you can build to Android and use SideQuest to quickly load the build to your Oculus for testing.
The Web Installer, will let you install SideQuest directly on your Oculus. I will be using the Advanced Installer for my PC, so I can enable developer mode as well as having access to more features than the Web Installer is capable of.
First, go to the Oculus dashboard and sign in. If you haven’t done so already, you will need to register as a developer.
You may be prompted to enter the name of your Organization, which can be anything you want if you are a solo developer or making a personal account.
Enable Developer Mode
Put on your Oculus headset and then navigate to Menu > Devices > Headset Settings > Developer Mode to activate the toggle.
You can now connect your Oculus to your PC with a USB / USB-C cable.
Back in the Oculus, select the option to allow access to data.
Your Oculus should now show up as connected in the SideQuest App.
If by chance your headset is still not connected, click the Open Setup Instructions button and SideQuest will help you troubleshoot with it’s built-in diagnostics tool.
Building to Android
After building to Android in Unity, you can use the download looking button in SideQuest to install your APK from a folder on your computer.
In SideQuest, You can also see your currently installed apps and manage files on your Oculus.
After installing your APK, you may need to enable apps from Unknown Sources in your Oculus headset. Do do this, navigate to Settings > General > Unknown Sources to enable the toggle. You should now be able to go to your All Apps menu, and change the filter at the bottom to Unknown Sources, which should show your applications.
Unity and VR
Unity 6 has some great options for VR, such as their default VR scenes in URP and HDRP, as well as a multi-player VR template scene. I will dive into VR in Unity 6 here soon, but for these next introductory articles, I will be using Unity 2021.3.16f1 and the URP 3D core template.
XR Plugin Management
In order to connect your PC to the Oculus and use it via Quest Link, you can go to the Package Manager and install the XR Plugin Management package. The XR Plugin Management basically does what it says, and manages all of your VR plugins.
Viewing Your Unity Scene in the Oculus
The following is only applicable if you are using Oculus Link to play-test live, not for building to Android with SideQuest.
After installing the XR Plugin Manager, navigate to Edit > Project Settings > XR Plugin Management, to enable the needed Plug-In Providers. Make sure to check the Initialize XR on Startup option.
If you enable the Oculus tick-box, the Oculus XR Plugin will automatically be installed into your project, via the XR Plugin Management. The Oculus XR Plugin, is what is actually communicating between your computer and headset.
The last thing to do is to put on your headset, then go to the Quick Settings Menu and select Quest Link and then Launch. Once you press Play in Unity, you should be able to see your VR scene in the Oculus.
XR Interaction Toolkit
Head back to the Package Manager and install the XR Interaction Toolkit. The VR controls use the Input System, so you may be prompted to switch over from the legacy input.
When you go to create a new game object, you should see an new XR menu option that comes with a variety of XR and VR related pre-made Unity game objects.
Back in the Package Manager, there are some great Starter Assets to install via the XR Interaction Toolkit page.
In order to find the VR Starter Assets after installation, navigate to Assets > Samples > XR Interaction Toolkit > Version Number > Starter Assets.
Here you will find a lot of Unity presets for VR components. Basically, Unity did a lot of work so that we don’t have to (thank you Unity devs!).
There is also a great VR demo scene you can play with to explore some premade Unity VR interactions.
Unity also provides an Input Actions Asset, which is Unity’s awesome cross-platform input solution. If you want to learn more about Unity’s Input System, you can read my series of articles below.
The last Starter Asset in the Prefab folder I will talk about, is the Complete XR Origins Prefab. You can simply drag the prefab into your VR scene and have a working rig to start with!
Over my next few articles, I will dissect this prefab to gain a better working knowledge of each component and how to re-build this prefab from scratch. For now, thanks for reading and happy VR exploration!