Unity XR - Unity crashes on Play exit with Oculus Integration

Date: 2021-09-25T16:22:09+00:00 - (Skid Vis)

If you’re developing VR applications with Unity and Oculus Integration, you might have encountered a frustrating issue: Unity crashes every time you exit Play mode. This problem has been affecting many developers, particularly with Oculus Integration version 32. In this guide, I’ll walk you through the exact steps to fix this issue and get your development workflow back on track.

The Problem

When using Oculus Integration in Unity (particularly version 32 at the time of this writing), you may experience the following scenario:

  1. You enter Play mode to test your VR application
  2. Everything works fine while in Play mode
  3. When you click the Play button again to exit Play mode, Unity crashes with an error related to UnityEngine.SubsystemBindings.DestroySubsystem

This crash is not caused by your code or project setup - it’s related to how the Oculus Integration package interacts with Unity’s XR systems, particularly around the new OpenXR backend.

The Solution: Step-by-Step Guide

The fix involves reinstalling the Oculus Integration package and making specific choices during the setup process. Here’s how to resolve the issue:

Step 1: Remove the Current Oculus Integration

First, we need to completely remove the current Oculus Integration package:

  1. Navigate to your project’s Assets folder
  2. Find and delete the Oculus folder (this contains the Oculus Integration assets)
  3. Reopen your Unity project

At this point, you’ll notice that any Oculus-related components in your scene (like the OVR Player Controller) will be missing their references.

Step 2: Reinstall Oculus Integration

Now we’ll reinstall the Oculus Integration package, but with specific settings:

  1. Open the Package Manager (Window > Package Manager)
  2. Switch to “My Assets” (you may need to be logged into your Unity account)
  3. Find and select “Oculus Integration”
  4. Click “Download” or “Import” (depending on whether you’ve downloaded it before)
  5. In the import window, select all assets (or customize as needed for your project)
  6. Click “Import”

Step 3: Critical Setup Choices

This is the most important part. After importing, you’ll receive a series of popup dialogs. Here’s how to respond to each one:

  1. First popup - “New plugin detected
” - Click Yes

    • This acknowledges the Oculus plugin
  2. Second popup - “OpenXR Backend
” - Click Cancel

    • This is crucial! Do NOT select “Use OpenXR” as this is what causes the crashes
    • By clicking Cancel, you’re sticking with the legacy OVR plugin which is more stable
  3. Third popup - “The standard legacy OVR plugin will be activated by default
” - Click Restart

    • This confirms you want to use the legacy plugin and restarts the editor
  4. Fourth popup - “Audio Spatializer Plugin
” - Click Yes

    • This updates the audio spatializer plugin
  5. Final popup - “Plugin was updated
” - Click Restart

    • This completes the installation and restarts the editor again

Step 4: Verify the Fix

After Unity restarts:

  1. Set up your scene again if needed (re-add any missing Oculus components)
  2. Enter Play mode to test your VR application
  3. Exit Play mode

Unity should now exit Play mode without crashing!

Why This Works

The key to fixing this issue is avoiding the OpenXR backend that’s included in Oculus Integration. While OpenXR is the future standard for XR development, the implementation in Oculus Integration version 32 has compatibility issues with Unity’s subsystem management.

By choosing the legacy OVR plugin instead, you bypass these compatibility issues while still having full access to Oculus functionality.

Additional Tips

Conclusion

This seemingly simple issue can cause major headaches for VR developers, leading to lost time and frustration. By following the steps outlined above, you can avoid the Unity crashes when exiting Play mode and maintain a smooth development workflow.

Remember that VR development tools are constantly evolving, and sometimes these kinds of issues arise during transitional periods between different standards and implementations. Staying informed about workarounds like this can save you countless hours of troubleshooting.

If you’re experiencing this frustrating crash, check out my solution in the video walkthrough here.

For those working on VR projects, I recommend checking out VRIF (VR Interaction Framework) which you can find at: https://tinyurl.com/vrframework

I’d love to chat with you about any VR development challenges you’re facing! Join my Discord server at: https://discord.com/invite/CVNuqSZ

If you appreciate my content, please consider becoming a Patreon member: http://www.patreon.com/sharkjets

The music In this tutorial is by Flawed Human Being, who you can find on Spotify: https://open.spotify.com/artist/0ywnFmJWQwP4adEG9otvYA