Running in 30 mins: Virtual Reality Development Basics with Unity and Oculus

Haylen Rose
12 min readAug 17, 2021

--

Please find the code for this tutorial on my GitHub here

You’ve been looking at VR for the past few years, probably even tried out a few platforms. However, with the features, price point and portability of the Oculus Quest 2 — you decided it’s time to do a deep dive and make the purchase.

After a few weeks with your new Quest 2, you are not disappointed — but as an innovative ‘tinker’ and software engineer, you now want to go under the hood.

Maybe you’re looking into creating your own experience or interested in if VR tech makes sense to include in some new tech solution you’re architecting for a larger project. Either way you’re wondering about committing the time to learning the basics to see what you can do with your device — it’s a lot easier than you think!

This article will get you going with the basics and your general setup. By no means a comprehensive ‘basics’ tutorial, you will still get a quick base that will allow you to go deeper with additional resources if you need to (great links in the references section below).

What you’ll need

Unity (Mac or Windows) — Previous knowledge of this is not needed, but can help if you are diving deeper.

Android Development tools — Previous knowledge of this is not needed, but can help if you are diving deeper.

Oculus Quest 2 — You’ll need a device to test on, however you can still get most everything going without this if you wish to use the included simulator.

Setting up Unity

First we’ll need to download the latest stable version of Unity. You can get Unity Hub here: Download Unity Hub. This allows you to install Unity itself and manage modules and projects later on.

Once installed, let’s set the license to free/personal (unless you have a paid license already). Navigte to the Licence Management section under settings and click the “Activate New License” button.

Select the options that allow you to use the free personal License!

Next, let’s install Unity itself. From the main screen, go to the installs section.

Us the ‘Add’ button to add a new install. Select a version that is greater than 2019.4 or later (XR interactions was supported after this). Additionally, choose a version that is LTS (Long Term Support).

Hit next and ensure the following Modules are checked. NOTE if you have the Microsoft Visual Studio Community module as an option, you’d want to select that as well.

At this point, it will take some time to download and install, go get some coffee!

Setting up Android Studio tools and Side-loading

This step is specific to if you are using an android based device like the Oculus. To be able to compile and side load to the device we’ll need to have Android Studio tools installed. This is a pretty simple process and should be relatively easy.

First down Android Studio and install. Once installed open the application and the go to the preferences dialog.

At this dialog, fo down to the Android SDK section and select any version higher than API level 23 by checking the appropriate box and then clicking apply.

Within the same dialog, go to the ‘SDK Tools’ tab and ensure that you have the following items selected as well.

This should ensure that your Android development environment is setup and configured.

Setting up your Oculus Headset

To be able to deploy to your Oculus, you’d have to set configure it for developer mode. This is basically the same steps to allow side-loading of apps — so you can skip this if you already side-load apps to your Quest!

The steps are pretty simple for this part. You will go to the Oculus Developer portal and login using your Facebook/Oculus credentials (the ones used on your Quest). There, you will create a new organization with the name of your choosing and agree to the terms.

Next, we enable developer mode from your Oculus mobile app. Open the Oculus mobile app on the device used to setup your Oculus. Navigate to the Developer Mode option and ensure it is on.

Next, reboot your headset. After rebooting, you should be able to verify that developer mode is now on by checking that you have the “Developer” options in your settings menu of your Oculus.

Note: When you push the compiled app to the headset (or side-load other apps), it will appear in the ‘Unknown Sources’ Section of the apps menu.

Basic Hello world VR Project

Ok, now that you’ve got everything installed, configured and some coffee in your system, let's setup a basic project that will allow you to build VR experiences. You will have to do this for each Unity project you create that you’d like to do VR with.

On the main Unity screen, navigate to projects and click “New”, selecting the version of Unity you installed earlier.

Next fill in the details and select the “Universal Render Pipeline” template, and click “Create”.

Now that your project is created and opened (it may take a few minutes), we’re going to add the packages that will help you get a basic VR experience going.

From the main screen, go to Window>Package Manager.

From the Package Manager window, we now want to install a few packages from the Unity Registry. First make sure that the “Unity Registry” is selected.

Then “Preview Packages” in settings is enabled

Next, use the search functionality to find and install the following packages. Each package will take a few minutes to install and restart the project.

  • The ‘XR Interaction Toolkit’ package
  • The ‘XR Plugin Management’ package
  • The ‘Oculus XR Plugin’

Next we will want to adjust the project build settings. We’ll need to “Switch Platform” to Android

It takes a few minutes to switch the platform. Once this is done, we’ll need to set the Texture Compression to ASTC

Next we update the Project Settings with the following

Ensure that the XR Plugin Management is set to use Oculus

We then need to update the Player settings in the same project settings dialog

First set a name that will be easiest for you to find when the game is installed on your Oculus

Then ensure that the “Minimum API” for the Android settings is set to 23. Note, there’s a lot of settings on that page, you should just need to scroll down a bit to find it.

Now that we have everything configured, let’s create our own basic scene that we can work with.

You should be presented with a sample scene as shown below. You’ll be able to access your scenes by going to the assets>scenes folder shown below.

At this point, if you click the play button in the main screen, you will see that the application switches to the “Game” tab where you can now move the camera around using the keyboard arrows and the mouse.

This is a basic sample scene and you can use it as a playground. However for our purposes, we’ll actually need to use the XR components to create the camera so that it can work with our VR headset. Let’s do this in a new scene for the project.

Right click in the Scenes folder and create new scene and name it.

By double clicking on your new scene “VRhelloworld” it will now open up a clean scene in the editor.

Next, we want to create a basic plane as well as a few simple objects that we can see and interact with. Unity makes this simple, you can right click in the hierarchy of objects for the scene and go to the 3D object section to add a Plane as well as some shapes to form a table and a tablet with some text on it.

After selecting the object you want to add, it will appear in the scene. From there you can use the different tools to manipulate the size and orientation.

You are also able to set the material used for the objects you add.

Create a new material in the “Materials” project folder. Next set the name and colour you wish.

To set the cube to the new material “white” simple drag the new material over the cube with your mouse.

Create a table by inputing the values for position and scale as shown

Next remove the default main camera be right clicking on it and selecting delete.

Let’s then add a cube to form our tablet by adding a cube with the following information.

We’ll also set the tablet a bit over the table so that we can see it drop. However we’re going to need some additional scripting on the object to allow it to fall when the experience begins.

In the inspector pane on the right, click the “Add Component” button to the bottom and add the “RigidBody” component.

Next we want to setup an Rig with a camera to act as the player and respond to input from the headset tracking and controller tracking.

Add an empty game object and name it “VR-Rig” and set the position as shown.

Next, let’s add the “XR rig” component to the empty game object

Now we need to add the camera. To do this we’ll create another empty game object under “VR-Rig” and name it “CameraOffset”

Next we create the actual camera under the “CameraOffset” object. This will allow the offset of the camera to be adjusted in relation to the Rig. This time, you select create a “Camera” object. Add the “Track Pose” component to the camera with the settings shown. This will act as the eyes for the player and use the VR headset tracking to move.

Next, go back to the VR-Rig Settings and set the new objects as shown

Next up, let’s add a script to the camera that will allow you to control the view using your keyboard when running the app in the unity simulator.

Go to the camera and add a component “Simple Camera Controller” with the shown options.

OK, now let’s test on the headset!

Power up your headset and plug it into your computer. Next navigate back to the Build Settings and ensure that you add the new scene we created. Ensure that the SampleScene is not checked.

Click build and run! Note you may have to authorize your computer on your headset in VR the first time you Build and Run. Once compiled on the computer, it will automatically be side-loaded and started on yout device.

Great, you should be able to see the tablet we built just drop on the table and your headset should be tracked as you move around.

Lastly, no Hello World would be complete with “Hello World”. Let's place some text on that tablet!

Note that we added the text as an object under the tablet object in the hierarchy this will tie the text to move with the tablet.

You’ll see that a “Canvas” object was added, as well as a text object. Next set the properties including positioning for those two objects as follows.

Notes on Project Setup

There are two main ways you can setup a project for VR. You can use the newer XR integration packages from Unity that allows you to build for most VR setups including Oculus OR you can use the Oculus integration packages. Most resources online seem to suggest that XR is the more modern way to go so I’ll use that for this article.

It should be noted though, the Oculus Integration packages seem to give you quit a few Oculus specific things really quickly and easily. I’ve not looked as deeply into the Oculus Integration packages yet but will post an update after I get to dig into those a bit better.

Conclusion

Now we have a development environment setup that deploys to our device for testing. As well we were able to build a basic Hello World that shows the very essentials for a VR experience.

There’s many good resources to dig a lot deeper on this, hopefully this will give you a springboard to move faster through more advanced tutorials.

For completion, I’ll be adding two more articles following on this on where we’ll look at adding in your controllers and allowing interactions with the tablet and another that will allow us to use teleportation and direct movement with your controller. I’ll add the links to this article when these are posted later in the month.

Reference Links

Great video resources for getting setup as well as getting deeper into VR development. This video will give some basics I outlined, but check out his full youtube channel for a goldmine of great tutorials for VR development

If you need hand tracking you may have to wait or use the Oculus Integration packages instead of XR

--

--

Haylen Rose

Technologist, Entrepreneur, Agile advocate, Software Engineer, proud female activist who happens to be transgender