UAudioComponent playing only in Standalone, no sound in PIE.

Hi! I’m pretty new to C++, but I’ve been working with audio for a while. One of the first things I wanted to do was to create a SoundManager, a singleton class that persists across levels and manages important audio info and parametres, as well as handles high level music in the game(MainMenu, Level Transitions etc).

So I did just that, created a SoundManager class, derived from UObject, and store it in my GameInstance.
On Game instance init() I call SoundManager’s own init, where I handle UAudioComponent creation, setting sound and playing. But here’s the catch, it works perfectly fine while playing in Standalone, but I have completely no luck playing it in PIE Viewport.

No matter what I did, GEngine, GI, World, UAudioComponent and ActiveAudioDevice are valid. Please help me.
Code snippets below:

MyGI

void UMyGameInstance::Init()
{
	Super::Init();

	InitializeSoundManager();
}

void UMyGameInstance::InitializeSoundManager()
{
	// TODO Need to laod SoundManagerBPClass from setting and not from path
	UClass* SoundManagerBPClass = LoadClass<USoundManager>(nullptr, TEXT("/Game/Audio/Blueprints/BP_SoundManager.BP_SoundManager_C"));
	if (SoundManagerBPClass != nullptr)
	{
		SoundManagerInstance = NewObject<USoundManager>(this, SoundManagerBPClass);
		if (SoundManagerInstance != nullptr)
		{
			SoundManagerInstance->Initialize();
		}
	}
}

My SoundManager

void USoundManager::Initialize()
{
	UMyGameInstance* MyGI = Cast<UMyGameInstance>(GetWorld()->GetGameInstance());

	MainSoundComponent = NewObject<UAudioComponent>(GetTransientPackage(), NAME_None, RF_Transient);
	MainSoundComponent->RegisterComponent();
	MainSoundComponent->Activate();

	MainSoundComponent->bAutoDestroy = true;
	MainSoundComponent->bIgnoreForFlushing = true;
	MainSoundComponent->bAllowSpatialization = false;
	MainSoundComponent->bCanPlayMultipleInstances = false;
	

	OnInitialize();
}

UAudioComponent* USoundManager::PlayMainUESound(USoundBase* SoundToPlay, float FadeInTimeDuration)
{
	if (IsValid(SoundToPlay))
	{
		MainSoundComponent->SetSound(SoundToPlay);
		MainSoundComponent->FadeIn(FadeInTimeDuration);

		return MainSoundComponent;
	}
	else
	{
		return nullptr;
	}
}

In my blueprint class I just call PlayMainUESound function.

Wwise works just fine

Please help me! Thank you.

So after much time tweaking things I found out that the problem was new audio device creating in PIE. You can disable that in your editor preferences by toggling off “Create New Audio Device for Play in Editor”.

I tried to move my UAudioComp initialization from GI’s Init() to GI’s OnStart(), in hopes that initializing it a little bit later will fix things, but it didn’t. No matter what I do, my UAudioComp keeps initializing on AudioDevice 1, while the session is running on AudioDevice 7. But it works fine in standalone, so there’s that.