Building Quest 2 VR Projects with Unity

Introduction

This tutorial will explain how to build a empty Unity VR project to the Meta Quest 2, Quest 3 or Quest Pro using the XR Interaction Toolkit package.

At the end of this tutorial you will have a simple and clean template project with a scene that has the Head and Controller tracking already setup built to your Quest device.

You can then use this project as a starting point for all your Quest VR Projects!


For this Project you will need:

  • a Windows or Mac computer with Unity installed. (This project uses Unity 2022.3.7f1 LTS)
  • a Meta/Oculus Quest VR Headset with USB cable
  • a Smart phone, iOS or Android

Step 1 Add the Android Build Module

Make sure the Android platform build module is installed in your Unity version because the Quest 2 is an Android device.

Open the Unity hub and go to Installs.
Select the Unity version that you’re going to use and click on the cog wheel then ‘Add Modules
Select Platforms > Android Build Support and click ‘Install‘:

Step 2 Create a New Project

In the Unity Hub go to Projects and select ‘New Project‘:


From the Templates select the ‘3D (URP) Core‘ template if you want to use the Unity Universal Rendering Pipeline or select the ‘3D Core‘ template if you want to use the regular built-in rendering pipeline and click on ‘Download Template‘:


Name your project something like ‘Quest2TestProject‘ (you can always change the name later) and click on ‘Create Project

Step 3 Change the Unity Build Target

In the Unity menu bar click on File > Build Settings:

In the Platform list select ‘Android‘ and click on ‘Switch Platform‘. Unity will re-import all the assets that are in the project so if you already have a large project it will take some time but if you started with an empty project this won’t take long:

Step 4 Install the necessary XR packages

In the Unity menu bar click on Window > Package Manager to open the Package Manager:

In the top left of the Package Manager window switch from Packages: In Project to Packages: Unity Registry to see all the available official Unity packages:

Scroll down the list of packages, select the ‘XR Plugin Management‘ package and click on Install. The XR Plugin Management facilitates the transfer of date from the VR headset into Unity and makes things like head tracking and controller tracking work:

In the Unity menu bar click on Edit > Project Settings to open the Project Settings window:

In the list of project settings select XR Plug-in Management and make sure that on the left side of the window the Android settings are selected (so not the Windows, Mac or Linux settings) and then enable the Oculus Plug-in Provider:

Open the Package Manager window again (Unity menu bar, Window > Package Manager) and install the ‘XR Interaction Toolkit’ package.
(The XR Interaction Toolkit is a collection of pre-made components/scripts that will allow you to quickly create a VR experience):

After installing the XR Interaction Toolkit package a pop-up window will appear asking if you want to use the new input system. Click on yes and Unity will restart to disable the old input system.

Step 5 Building a simple VR testing scene

Right-click in the Hierarchy view and click on XR > XR Origin (VR) to add a XR Origin GameObject to the scene:

(The XR Origin is basically enough to add VR head tracking to the scene so if you were to build the project now you would be able to look around the scene by moving your head.)

If you unfold the XR Origin GameObject in the Hierarchy view by clicking on the triangle in front of it you can see that it has Main Camera and Left and Right Controller child objects.
Because we only need one Main Camera in our scene you can delete the default Main Camera object that was already in the SampleScene from the Hierarchy view.

If you select the Main Camera from the XR Origin GameObject you can see in the Inspector view that it has a ‘Tracked Pose Driver’ component that already has Actions setup to get its Position and Rotation from the VR headset:

If you select the Left and Right Controller GameObjects in the Hierarchy view you can see in the Inspector view that the Actions for the Tracking and Input are still blank, but we can quickly fill those in by using presets…

Open the Package Manager window (Unity menu bar, Window > Package Manager).
Select the XR Interaction Toolkit package in the Packages list.
Click on the ‘Samples‘ tab on the right side of the Package Manager window (next to Description, Version History, Dependancies) and import the ‘Starter Assets‘.
(The Starter Assets contain presets that will allow you to quickly fill in all the Actions on the Left and Right Controller GameObjects):

Select the Left Controller in the Hierarchy view and then click on the small button that looks like two sliders next to the name of the XR Controller (Action Based) component and next to the small question mark button in the Inspector view.
Select the ‘XRI Default Left Controller‘ presets file.
Do the same for the Right Controller and choose the ‘XRI Default Right Controller’:

As you can see all the Actions of the XR Controller component are now populated:

When you start the scene now you will see that there is a representation of your hands because of the LineRenderer and the XR Interactor Line Visual components on the Left and Right Controller.

Step 6 Building the project to the Quest headset

Open the Build Settings window (Unity menu bar, File > Build Settings) and select Android in the Platform list then click on Player Settings in the bottom left of the window:

In the Project Settings window under Player (with ‘Player’ Unity means the actual application that ‘Plays’ not the actual player of the game) change ‘Company Name‘ to something more personal:

Under ‘Identification‘ uncheck ‘Override Default Package Name‘ so it will be filled in with your company name.
Also under Identification set the ‘Minimum API Level‘ to ‘Android 10.0 (API level 29)‘:


Under ‘Configuration‘ switch ‘Scripting Backend‘ from ‘Mono’ to ‘IL2CPP‘.
Also under Configuration set ‘Target Architecture‘ to ‘ARM64‘ and set ‘Install Location‘ to ‘Automatic‘:

Grab your iOS or Android smart phone and install the Meta Quest app:

In the Meta Quest App select ‘Menu‘ in the bottom right corner and then select ‘Devices‘.
Pick Quest 2 from the list of devices to connect to your headset.
Tap on Headset settings > Developer Mode and toggle Developer Mode on:

Connect your headset to your computer with the USB cable.
A popup will appear in the headset asking if you want to ‘Allow USB debugging’ so press on ‘Allow’.
Also press on Allow in the popup that asks if you want to ‘Allow access to data’.

In Unity open the Build Settings window (Unity menu bar, File > Builds Settings).
Select Android in the Platform list and press on ‘Refresh‘ next to ‘Run Device‘.
Switch the Run Device from ‘Default device‘ to ‘Oculus Quest 2‘:

Click on ‘Build And Run‘ in the bottom right of the Build Settings window and give your build a name.
Make sure your headset stays connected while Unity is building the app. When Unity is done building, the app will be installed on your Quest and will automatically start:

When you close the app in your Quest and when you want to reopen it again later you’ll notice that it doesn’t show up in the list of Apps that you have installed on your Quest.
In order to start your own homemade apps on the Quest you’ll have to click on the search bar in the Apps window:

and then switch the filtering from ‘All‘ to ‘Unknown Sources‘:

From there you can launch all your own Unity builds:

That is it for this tutorial!

Hopefully this clean project template will help you to create elaborate Quest VR games for me to play in the future 😉

If you’re looking for a much more in depth Unity VR tutorial then check out the Unity VR Roller Coaster Shooter Tutorial over here:

Website Powered by WordPress.com.