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.