Download

Best place to "load" AudioVolumeSettings? (SoundClasses)

Hey there,

copying this question of mine from the AnswerHUB, since it feels like no one can answer it over there.

I’m currently working on a Settings Menu for the Main Menu and In-Game Menu.

For the AudioVolume, I created 3 SoundClasses, 1 Parent Class and 2 Children.

When setting the AudioSettings in my Settings Menu, I use the UGameUserSettings Class,
of which I have a Child with an overridden ApplySettings(…) function.

It iterates through the AudioDevice SoundClasses and applies the Values based on their names:



void UBMGameUserSettings::ApplyAudioSettings()
    {
    	if (GEngine)
    	{
    		FAudioDevice* ADevice = GEngine->GetMainAudioDevice();
    
    		if (ADevice)
    		{
    			for (auto Itr = ADevice->SoundClasses.CreateIterator(); Itr; ++Itr)
    			{
    				USoundClass* SoundClass = Itr.Key();
    
    				FString SoundClassName;
    
    				if (SoundClass->GetFullName().Split(L".", nullptr, &SoundClassName, ESearchCase::CaseSensitive))
    				{
    					// Set one of the twoClasses
    				    if (SoundClassName == "BMSoundClass_Music")
    					{
    						SoundClass->Properties.Volume = MusicSoundVolume;
    					}
    					else if (SoundClassName == "BMSoundClass_SFX")
    					{
    						SoundClass->Properties.Volume = SFXSoundVolume;
    					}
    					else
    					{
    						SoundClass->Properties.Volume = GlobalSoundVolume;
    					}
    				}
    			}
    		}
    	}
    }


This is all working fine. The Float Numbers are saved in the GameUserSettings.ini and are correctly loaded back into the Menu when reopening it. But now I face the problem of actually applying the Settings on Startup.
Because right now, I need to press “ApplySettings” again to apply the SoundVolume again. While the Numbers are saved and loaded, the “Applying” is missing.

It tried calling the ApplyAudioSettings function on LoadSettings of the GameUserSettings class, but that seems to happen WAY too early, so the SoundClasses aren’t yet spawned.

This setting needs to be applied to all SoundClasses. The ones of the MainMenu and every following Level.

What’s the best place to call that, so it’s called at the correct time, every time a new Level is opened?

If you need more information, just tell me. Thanks in advance!

Cheers!

Bump! I still don’t know where I need/want to load SoundVolume Settings.

what you could do is to set the property whenever the soundclass is created. You can do this by calling GetDefault<UBMGameUserSettings>()->MusicSoundVolume.