# VR. Setting Oculus Rift audio driver on Unity

**URL:** <https://qa.fmod.com/t/vr-setting-oculus-rift-audio-driver-on-unity/16635>\
**Category:** Unity\
**Created:** [January 13, 2021, 12:33pm UTC](https://qa.fmod.com/t/vr-setting-oculus-rift-audio-driver-on-unity/16635 "2021-01-13T12:33:25Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![PepitoGrillo24](https://avatars.discourse-cdn.com/v4/letter/p/ecd19e/32.png) [@PepitoGrillo24](https://qa.fmod.com/u/PepitoGrillo24)\
**Post date:** [January 13, 2021, 12:33pm UTC](https://qa.fmod.com/t/vr-setting-oculus-rift-audio-driver-on-unity/16635/1 "2021-01-13T12:33:25Z")

</div>

Hi.  
We are sending our game to the Oculus team and they are reporting that the game “must target the audio device selected in the “Audio Output in VR” setting in the Oculus app.”

We have pasted the code snippet that can be found on their website, but nothing seems to work. I also changed the deprecated “getLowLevelSystem” for the “getCoreSystem”, but nothing seems to work.

> ```
> FMOD.RESULT Initialize()
> {
> 
> ```
> 
> #if OCULUS && !UNITY\_ANDROID  
> FMOD.System sys;  
> FMODUnity.RuntimeManager.StudioSystem.getCoreSystem(out sys);
> 
> ```
> int driverCount = 0;
> sys.getNumDrivers(out driverCount);
> 
> string riftId = OVRManager.audioOutId;
> 
> int driver = 0;
> while (driver < driverCount)
> {
> System.Guid guid;
> int rate, channels;
> FMOD.SPEAKERMODE mode;
> sys.getDriverInfo(driver, out guid, out rate, out mode, out channels);
> 
> if (guid.ToString() == riftId)
> {
> break;
> }
> 
> ++driver;
> }
> if (driver < driverCount)
> {
> sys.setDriver(driver);
> }
> 
> ```
> 
> #endif

Maybe we are putting the code on a wrong place?

---

<div class="post-metadata">

**Author:** ![mathew](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/mathew/32/431_2.png) [@mathew](https://qa.fmod.com/u/mathew)\
**Post date:** [January 14, 2021, 4:30am UTC](https://qa.fmod.com/t/vr-setting-oculus-rift-audio-driver-on-unity/16635/2 "2021-01-14T04:30:55Z")

</div>

We recently made handling Oculus driver selection a lot easier and provide an example specifically for implement that behavior. Check out our [Unity docs](https://fmod.com/resources/documentation-unity?version=2.1&page=examples-oculus-setup.html) for details.

---

<div class="post-metadata">

**Author:** ![PepitoGrillo24](https://avatars.discourse-cdn.com/v4/letter/p/ecd19e/32.png) [@PepitoGrillo24](https://qa.fmod.com/u/PepitoGrillo24)\
**Post date:** [January 14, 2021, 11:51am UTC](https://qa.fmod.com/t/vr-setting-oculus-rift-audio-driver-on-unity/16635/3 "2021-01-14T11:51:08Z")

</div>

In order to prevent problems, we would like to avoid a major version upgrade. We are currently using the version 2.0.10 and the game is already published in some stores.  
The last build I sended to them was this one. But they still report that there’s no audio through the target device.

```
    public void PreInitialize(FMOD.Studio.System studioSystem)
    {
        string riftId = OVRManager.audioOutId;
        FMOD.System coreSystem;
        FMOD.RESULT result = studioSystem.getCoreSystem(out coreSystem);

        int driverCount = 0;
        result = coreSystem.getNumDrivers(out driverCount);
        for (int i = 0; i < driverCount; i++)
        {
            int rate;
            int channels;
            System.Guid guid;
            FMOD.SPEAKERMODE mode;

            result = coreSystem.getDriverInfo(i, out guid, out rate, out mode, out channels);

            if (guid.ToString() == riftId)
            {
                result = coreSystem.setDriver(i);

                break;
            }
        }
    }

```

> FMOD.RESULT Initialize()  
> {  
> #if OCULUS && !UNITY\_ANDROID  
> PreInitialize(studioSystem);  
> #endif

---

<div class="post-metadata">

**Author:** ![mathew](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/mathew/32/431_2.png) [@mathew](https://qa.fmod.com/u/mathew)\
**Post date:** [January 14, 2021, 10:20pm UTC](https://qa.fmod.com/t/vr-setting-oculus-rift-audio-driver-on-unity/16635/4 "2021-01-14T22:20:02Z")

</div>

Understood, it looks like you are calling PreInitialize at the top of RuntimeManager.Initialize, at this point the Studio System won’t have been created yet. Try moving your call to PreInitialize down to just before the call to studioSystem.initialize, line 244 in the version I have here.

---

<div class="post-metadata">

**Author:** ![PepitoGrillo24](https://avatars.discourse-cdn.com/v4/letter/p/ecd19e/32.png) [@PepitoGrillo24](https://qa.fmod.com/u/PepitoGrillo24)\
**Post date:** [January 20, 2021, 9:47am UTC](https://qa.fmod.com/t/vr-setting-oculus-rift-audio-driver-on-unity/16635/5 "2021-01-20T09:47:58Z")

</div>

It worked. Thanks Mathew.  
If someone has the same problem and needs to avoid upgrading to 2.1 for any reason, the snippet of code above should work. Just make sure you call this method after the “FMOD.Studio.System.create”.

---

<div class="post-metadata">

**Author:** ![changingday\_robbie](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/changingday_robbie/32/4890_2.png) [@changingday\_robbie](https://qa.fmod.com/u/changingday_robbie)\
**Post date:** [April 18, 2023, 9:20pm UTC](https://qa.fmod.com/t/vr-setting-oculus-rift-audio-driver-on-unity/16635/6 "2023-04-18T21:20:56Z")

</div>

Is there a way to do this without having access to OVRManager when utilising OpenXR? i.e. get the value OVRManager.audioOutId outputs some other way?

---

<div class="post-metadata">

**Author:** ![mathew](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/mathew/32/431_2.png) [@mathew](https://qa.fmod.com/u/mathew)\
**Post date:** [April 18, 2023, 11:43pm UTC](https://qa.fmod.com/t/vr-setting-oculus-rift-audio-driver-on-unity/16635/7 "2023-04-18T23:43:00Z")

</div>

The OVRManager is the one that knows the GUID of the VR audio endpoint. If that’s not available to you, then your other option is finding it by name (if it has a well known name).

---

<div class="post-metadata">

**Author:** ![rh\_galaxy1](https://avatars.discourse-cdn.com/v4/letter/r/94ad74/32.png) [@rh\_galaxy1](https://qa.fmod.com/u/rh_galaxy1)\
**Post date:** [November 18, 2023, 11:06am UTC](https://qa.fmod.com/t/vr-setting-oculus-rift-audio-driver-on-unity/16635/8 "2023-11-18T11:06:56Z")

</div>

How can this be accomplished with OpenXR and Unity? The Unity sound is playing on the right device, but I found no way of getting the Unity output device GUID, or the OpenXR device GUID.

This may not be an FMOD question, but on the right topic at least, since OpenXR is the current way. How do people do it?

Also it is not easy to do it by name, since getDriverInfo does not report a name.

---

<div class="post-metadata">

**Author:** ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)\
**Post date:** [November 21, 2023, 12:22am UTC](https://qa.fmod.com/t/vr-setting-oculus-rift-audio-driver-on-unity/16635/9 "2023-11-21T00:22:32Z")

</div>

Hi,

Would it be possible to elaborate on the issue you are facing? What version of the FMOD Integration and Unity are you using?

FMOD should natively output to the Oculus Rift, is there any code that you have implemented to try to select an output device? Would it be possible to see this if so?

---

<div class="post-metadata">

**Author:** ![rh\_galaxy1](https://avatars.discourse-cdn.com/v4/letter/r/94ad74/32.png) [@rh\_galaxy1](https://qa.fmod.com/u/rh_galaxy1)\
**Post date:** [November 21, 2023, 1:50am UTC](https://qa.fmod.com/t/vr-setting-oculus-rift-audio-driver-on-unity/16635/10 "2023-11-21T01:50:43Z")

</div>

I use FMOD Studio Unity Integration 2.02.07. Unity output for sound (outputs to headset), and FMOD for music (outputs on device 0 - the selected device in Windows).

I have no code to show, but if I knew the Oculus device GUID I would select it like in the example above. However, since there could be other headsets than Oculus, it would be nice if the device GUID could be retrieved from Unity or OpenXR…

---

<div class="post-metadata">

**Author:** ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)\
**Post date:** [November 24, 2023, 3:26am UTC](https://qa.fmod.com/t/vr-setting-oculus-rift-audio-driver-on-unity/16635/11 "2023-11-24T03:26:21Z")

</div>

Hi,

The issue may be using both the Unity audio and FMOD as they will be competing for resources. More information can be found here: [Unity Integration | Trouble Shooting - Disabling Unity Audio](https://fmod.com/docs/2.02/unity/troubleshooting.html#disabling-unity-audio).

A way to get the GUID of the Rift would be to use [FMOD Engine | Core API Reference - System::getDriverInfo()](https://fmod.com/docs/2.02/api/core-api-system.html#system_getdriverinfo), which returns both the name and the GUID of the driver, you could just check for the name `"Headphones (Rift Audio)"` and the associated GUID. The easiest way to iterate through all the currently attached drivers is to use [FMOD Engine | Core API Reference - System::getNumDrivers()](https://fmod.com/docs/2.02/api/core-api-system.html#system_getnumdrivers) and use the value to check all devices for the correct name.

Hope this helps!

---

<div class="post-metadata">

**Author:** ![rh\_galaxy1](https://avatars.discourse-cdn.com/v4/letter/r/94ad74/32.png) [@rh\_galaxy1](https://qa.fmod.com/u/rh_galaxy1)\
**Post date:** [November 24, 2023, 3:57am UTC](https://qa.fmod.com/t/vr-setting-oculus-rift-audio-driver-on-unity/16635/12 "2023-11-24T03:57:17Z")

</div>

Thanks, I didn’t have to disable Unity audio but may do so in the future.  
Also I didn’t see that getDriverInfo could return a name as a second option.

Still feels like I’m not getting every headset, or even the right headset, but it is better than before.

if (name.Contains(“Rift”) || name.Contains(“Oculus”) || name.Contains(“VIVE”))

---

<div class="post-metadata">

**Author:** ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)\
**Post date:** [November 27, 2023, 1:34am UTC](https://qa.fmod.com/t/vr-setting-oculus-rift-audio-driver-on-unity/16635/13 "2023-11-27T01:34:33Z")

</div>

Hi,

Checking if that was able to resolve the issue or if there was anything else we could assist with?

---

<div class="post-metadata">

**Author:** ![rh\_galaxy1](https://avatars.discourse-cdn.com/v4/letter/r/94ad74/32.png) [@rh\_galaxy1](https://qa.fmod.com/u/rh_galaxy1)\
**Post date:** [November 27, 2023, 1:54am UTC](https://qa.fmod.com/t/vr-setting-oculus-rift-audio-driver-on-unity/16635/14 "2023-11-27T01:54:06Z")

</div>

That’s it for now.
