Packaged project defaulting to Rift audio device in non VR

First, my Default Audio Device setting is clear, so it should be choosing the default windows device.

My default windows device is my spakers. When I play my game in non (without the -VR tag), it loads up in non VR properly, but the audio is defaulting to my rift… despite the visuals being on my monitor and HMD enabled detected as false.

This only happens for my packaged game… in editor, it behaves as expected, sending the audio to my rift only in VR preview, and my speakers otherwise.

This has been bugging me for a while. Seems like a bug since it should be choosing the default windows device, as I left the section clear.

The -VR thing wasn’t known to me. It looks like this is used in conjunction with a general project settings in UnrealEngine.cpp to determine if the engine starts up stereo rendering mode.

The audio code that decides on whether or not to use the HMD audio device or windows default is in FXAudio2Device::InitializeHardware() in XAudio2Device.cpp in the old audio engine and MixerDevice::InitializeHardware().

In audio mixer code, it’s this:

			FString DefaultDeviceName = AudioMixerPlatform->GetDefaultDeviceName();

			// Allow HMD to specify audio device, if one was not specified in settings
			if (DefaultDeviceName.IsEmpty() && FAudioDevice::CanUseVRAudioDevice() && IHeadMountedDisplayModule::IsAvailable())
			{
				DefaultDeviceName = IHeadMountedDisplayModule::Get().GetAudioOutputDevice();
			}

Similar code in XAudio2Device.cpp. In both of these ases, CanUseVRAudioDevice() is called, which is the following:

bool FAudioDevice::CanUseVRAudioDevice()
{
#if WITH_EDITOR
	if (GIsEditor)
	{
		UEditorEngine* EdEngine = Cast<UEditorEngine>(GEngine);
		return EdEngine->bUseVRPreviewForPlayWorld;
	}
#endif
	return true;
}

It may work to directly check the -VR command line arg and return this in an an #else block, as follows:

bool FAudioDevice::CanUseVRAudioDevice()
{
#if WITH_EDITOR
	if (GIsEditor)
	{
		UEditorEngine* EdEngine = Cast<UEditorEngine>(GEngine);
		return EdEngine->bUseVRPreviewForPlayWorld;
	}
	else
#endif
	{
		return FParse::Param(FCommandLine::Get(), TEXT("vr")) || GetDefault<UGeneralProjectSettings>()->bStartInVR;
	}
}

Note you’ll have to include GeneralProjectSettings.h:

#include "GeneralProjectSettings.h"

I haven’t tested this yet, but it’s what I would do to fix this. If you can code/have time to verify this fixes the issue for you, I’d be super appreciative.

Also note that it appears VR supports flipping back and forth between VR and non-VR. The old audio engine doesn’t support audio device hotswap.

Unfortunately this didn’t do the trick.

However, I only use blueprints, I am not very familiar with actual programming so maybe I screwed up along the way. I added the include, I added the code you mentioned, and I saved the CPP files. Do I need to do anything else?

Awesome, thanks a ton! :smiley:

I just edited the post, had a compile issue. Woops.

Yeah, if you don’t know how to code, it’s going to be hard to walk through the other steps you’ll need to do. If you’re not using your own build, that means you’re using the UE4 launcher binary, which means you’ll need to switch everything out.

Unfortunately, to fix this would require some C++ patching and rebuilding everything.

We have a 4.17.2 patch coming out that I think I can squeeze this in. It should fix you.