Hi!
I have a function to ensure that the correct audio with correct level is playing when I enter any room. Now the problem is: when I lower the volume with the slider it works fine, even changing to a room with the same track but different attenuation works (3rd if-clause). BUT as soon as I change to a room with a different track, the volume is loud again (2nd if-clause).
function EnsureMusic(AudioClip* music, int attenuation)
{
_currentAttenuation = attenuation;
if (music == null)
{
CurrentMusic.Stop();
CurrentMusic = null;
}
else if (CurrentMusic == null || CurrentMusic.PlayingClip != music)
{
if (CurrentMusic != null)
CurrentMusic.Stop();
CurrentMusic = music.Play(eAudioPriorityNormal, eRepeat);
CurrentMusic.Volume = ValidVolume(_musicVolume - attenuation);
}
else if (CurrentMusic != null)
{
CurrentMusic.Volume = ValidVolume(_musicVolume - attenuation);
}
}
_musicVolume is only set when I change the slider. Why does setting the volume not work?
This is a bug with relation to the fading.
If a fade is set it will override your volume.
So line 13 causes the clip to play and then line 14 sets the volume
but then the volume is set to 0 again by the engine and the music is faded up to full volume.
So just disable the fading and handle it manually.
Ok, without fading it works correctly. Thanks!