Slider Value at 0.0 Sets Decibel Values to 0 even With Conversion Equation

I’m trying to convert the values of a slider’s values to a audio mixer’s decibel volume value.

public void Update(){
MainVolumeMixer.audioMixer.SetFloat("mainVolume", Mathf.Log(mainVolumeSlider.value) * 20);
}

I works from 0.00001 - 1.0, but when it reaches 0 it changes the decibels to 0. I’ve tried adding .000001 to the log itself and to the entire equation. None of these seems to fix it.

What do you think Mathf.Log(mainVolumeSlider.value) should resolve to when mainVolumeSlider.value is 0f? I haven’t tried it, but I’m guessing it is NaN, or infinity or something. You might be seeing a console error or warning on that line.

You probably want to grab the slider value first, then check if it is equal to 0f. If so, you skip the the Mathf.Log and just set the volume to whatever minimum value you want. If not 0f, then you run it through your current formula.

1 Like

https://discussions.unity.com/t/567394/23

I did try that, it didn’t work either.

Got it, I decided to clamp the value of the slider between .0001f and 1.0. I’ve been trying to use if and else statements.