paint-brush
Building An Oculus Quest 2 Compatible Game With Unity: A Beginner's Guideby@shiaart
8,519 reads
8,519 reads

Building An Oculus Quest 2 Compatible Game With Unity: A Beginner's Guide

by Art ShJuly 18th, 2023
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Creating for VR could sound as quite complex area, especially for someone building for web or mobile. I want to demonstrate that creating for VR is not that challenging at all. In this article, I'll guide you through creating a modern and robust Oculus compatible game in Unity. I'll also share a few tips how to optimize your asset for maximum performance and quality.
featured image - Building An Oculus Quest 2 Compatible Game With Unity: A Beginner's Guide
Art Sh HackerNoon profile picture

Creating games for VR could sound like quite a complex area, especially for someone building for web or mobile. While this is partially true, since we are entering an era of new types of devices, I want to demonstrate that creating games for VR is not that challenging at all. In this article, I'll guide you through creating a modern and robust Oculus-compatible game in Unity and share a few tips on how to optimize your asset for maximum performance and quality when building Quest headsets.


The key steps include:


  1. Setting Up your Unity Workspace
  2. Setting Up and configuring the Device
  3. Optimizing your project
  4. Running the App on the Device


Let's dive into each step more comprehensively.


Setting Up your Unity Workspace

To start, go to the Unity website and create an account. If you don’t have one, download Unity. The personal edition should be fine for the vast majority of projects.


Install the program in a location of your choice, and make sure you add Oculus Integration in the Asset store. Start Unity and create your new project.


Your Editor will look similar to this:

Creating a new project with Unity


Choosing project type


VR sample is a great starting point, and it comes with components that handle tracking the headset and controllers. Some settings still need tweaking so it knows what kind of headset to use.


Navigate to EditProject Settings, find XR Plug-in Management. Once found, select the Android tab and check the Oculus setting. You may see a similar setting below, but it may vary depending on the Unity version.


XR Plug-in Management



Quest 2 as a target device



Your Unity Editor might look like this after the project is created and configured (depending on the Unity version)

The project was created based on a VR sample


Now all set on a project level, let’s dive into device configuration.


Setting Up and configuring the Device

For development purposes, the Quest 2 headset has to be paired with the PC using a USB cable and to the Oculus phone app to enable some settings.


Instructions are available on Meta’s website here. Please follow the instructions from Oculus to pair the device to the PC and your mobile phone. Once your headset is paired, the key is to enable Development mode, open the Oculus mobile app, and go to the Devices tab. Choose Headset Settings, “Developer Mode” heading should be visible. Tap and enable the toggle. A prompt will appear to create a developer account. Follow the instructions from Oculus to turn on the developer mode.


The device is ready to go, but before we run the game on the headset, let’s check some optimization recommendations.


Optimizing your project

This seems to be quite early to explore since we are just starting with Quest and Unity, but I think it’s important to start thinking about performance and quality early in your journey.


Here is the list of areas I suggest you look at to make your experiences more performant:


  1. Set the stereoscopic rendering mode: In the Unity Player settings, under "XR Settings," set the stereoscopic rendering mode to "Single Pass Instanced" or "Single Pass Multiview." These modes optimize rendering for VR by reducing the rendering overhead.


  2. Optimize GPU performance: Use the Unity Profiler to identify and optimize GPU performance bottlenecks. Look for excessive draw calls, overdraw, and high GPU utilization. Optimize shaders, reduce the number of polygons, and minimize texture usage.


  3. Use static batching: Unity's static batching combines multiple small meshes into a single, larger mesh, reducing draw calls. Mark small objects as static and enable static batching in the Unity Player settings under "XR Settings" to improve performance.


  4. Optimize for mobile performance: Quest 2 is a mobile VR device, so optimizing for mobile performance is crucial. Optimize textures by reducing their resolution and using compression formats suitable for mobile platforms. Use fewer materials and simplify shaders when possible.


  5. Minimize CPU overhead: Avoid heavy scripting and computations that can strain the CPU. Optimize scripts by reducing unnecessary calculations, using object pooling, and avoiding expensive operations within Update loops. Use the Unity Profiler to identify CPU bottlenecks.


  6. Implement occlusion culling: Occlusion culling prevents the rendering of objects that are not visible to the player, reducing GPU load. Unity provides built-in occlusion culling tools that you can use to optimize your scenes.


  7. Use LOD (Level of Detail): Implement Level of Detail for 3D models to reduce the polygon count of objects as they move further away from the player. This helps improve performance by reducing the GPU load.


  8. Test and iterate: Remember that optimization is an iterative process! Regularly test your project on the Oculus Quest 2 hardware to identify performance issues. Use the Oculus Developer Hub and Unity Profiler to gather performance data and iterate on your optimizations.


I suggest saving this list or bookmarking it simply because this could be useful later in your Quest 2 journey or useful at any point in your development.


Let’s move on and finally see how to run the game on the headset.


Running the App on the Device

It’s time for the final step, and the most exciting part, running the app on the device.


Get back to the Unity project and navigate to File/Build and Run menu. This will open a window with various target platforms Unity can build for. Go with the Android option since the Oculus has Android as an underlying operating system.


From the settings listed in the left menu, the ones that should be modified for this first build are Texture Compression and Run Device. Set the compression to ASTC. From the Run Device dropdown menu, choose Quest 2 headset (the headset name will have an ID associated with the device). Click Refresh if there is no device listed. Make sure you add the current scene to the build by clicking Add Open Scenes button.


Build Settings window


Now is the time to try it yourself! Press Build and Run. The build will be saved. Once the building is done and successful, the game will be saved to the headset and launched. Put on the headset and try it yourself!


Wrap up

This is a baseline for creating virtual experiences for the Quest platform and headsets, but you can use it as a starting point and enable your imagination to build the most comprehensive and advanced games and experiences in VR. I think Quest 2 is a great device to start with and build for, we will see more advanced devices in the upcoming future, but the skills and knowledge you acquire while building for Quest 2 will help you advance in your developer journey.