Controling multiplayer game audio during a menu screen

Hello!

First time post.

I’m getting around learning the basic of coding 95% C++ in UE4.14.3.
Today I ran into a core dump (assert failure) problem attempting to mute active audio during a menu screen after testing the packaged version.



/* GameMenu.h */
...
    UPROPERTY(VisibleDefaultsOnly)
        UAudioComponent* AudioComp;
    UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Sounds")
        USoundCue* MenuLoop;
...
/* GameMenu.cpp */
...
    if (GEngine)
    {
        auto sounds = GEngine->GetActiveAudioDevice()->GetActiveSounds();
        for (auto sound : sounds)
        {
            UAudioComponent *audioComp = UAudioComponent::GetAudioComponentFromID(sound->GetAudioComponentID());
            if (audioComp->GetAudioComponentID() !=AudioComp->GetAudioComponentID())
            /////////////////////////////////////////// Crashes after this call
            GEngine->GetActiveAudioDevice()->PauseActiveSound(audioComp->GetAudioComponentID(),true); 
        }
    }
    AudioComp->SetSound(MenuLoop);
    AudioComp->Play();
...


When I run this code in debug mode, everything is fine.

When it is packaged Win64, a crash occurs in PauseActiveSound … check(IsInAudioThread()). The assembler code shows an int 3, which I believe is a debug break call.

Anyone have experience implementing basic c++ audio control in UE4, or know of any good samples for controling the vanilla engine audio in c++? The game I’m working on is a 4 person local network based multiplayer, with one of the clients acting as the server. The goal here was, to stop playing the ambient audio and all game audio, then start playing the setup/main menu audio track.

Thanks!
Cheers,
Eric

Hi!

I’ve just found old piece of code I wrote about year ago (for 4.10 or 4.11).
The point is change level(which is normalized value - from 0 to 1) of SoundClasses inside you created SoundMix.
https://gist.github.com/napolinkinpark3r/032cdc70f46b12fb3ba0d1d2ac30d4cb

Maybe it would help you! =-]

Hi,

Nice sample code. I’ll definitely consider it for level control.
So, are you saying, I should avoid pausing the active sounds and instead change the levels?

Thanks!
Eric

Seemingly, doing pause menu audio right, isn’t always trivial. :wink: