0 votes

1) I made some sliders to adjust the volume of the various BGM and sound effects, but realized that they're set to a linear scale, while audio works off of the logarithmic decibel scale.

Is there a way to set the audio scale to be logarithmic, or do I need to do that in the code?

2) Every time I enter the scene with the sliders, they reset their value to what they're set to in the Inspector menu. I want them to retain the values used when the screen was last open. I tried to pull the values from the audio buses in the _ready() function, but they get reset before entering that function.

Is there a way to either not trigger the value_changed() function when entering the tree, or to otherwise not overwrite the previous values?

Code:

func _ready():
     $SoundVolumeSlider.value = AudioServer.get_bus_volume_db((AudioServer.get_bus_index("SoundEffects")))

func _on_SoundVolumeSlider_value_changed(value):
    AudioServer.set_bus_volume_db(AudioServer.get_bus_index("SoundEffects"), $SoundVolumeSlider.value)
in Engine by (17 points)

1 Answer

+1 vote
Best answer

I don't know how to help with the first question, but the second one is easy. You have to save those changes somewhere, so you should save it for example in json or any txt file and make script that:
a) saves last settings
b) retains last saved settings

It should be easy to find such tutorial

by (46 points)
selected by

Thanks for the tip!

I also found that the functions db2linear() and linear2db() convert the values the way I want for #1 above.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.