Creating volume sliders in Godot 4
ฝัง
- เผยแพร่เมื่อ 22 พ.ค. 2023
- Here's the right way to let the user adjust the volume of different types of audio in your game.
Sample project: github.com/theshaggydev/the-s...
Text version: shaggydev.com/2023/05/22/volu...
Further reading
- docs.godotengine.org/en/stabl...
- docs.godotengine.org/en/stabl...
Damn, this is what a tutorial is supposed to look like. Short, informative and useful. Good job!
I have spent all fucking week trying to find a solution and here late at night at 01:23 on friday, with a new Indev releases every Saturday, thank you so much for literally de-stressing my whole week. You just earned a sub, like and a pin on my bookmark bar
On the next to last day of my first game jam. You are my HERO!
I see Shaggy Dev in my feed, and I click.
Your tutorials are still some of my favorite on TH-cam! Especially love some of your more technical videos!
Keep doing what you do dude!
Me too, any video from him is pure gold.
Thank you! Means a lot :)
Got some more technical videos in the works I think you'll like... if I can ever finish them, haha.
@@TheShaggyDev Awesome, glad to hear ;), one step at a time like everything else!
fantastic video. I very much appreciated the explanation for converting linear to db. Really handy information.
Very helpful, informative, and concise. Helped me do what I was trying to do quickly, thank you!
Great tutorial! Short and sweet and good quality
Great tutorial! Exactly what I need! Thank you!
Extrmely well done and informative thank you very much!
super video, thank you so much!
2:18
Without is literally just how Discord handles it.
THANK YOU
Thanks!!
Firstly, I tried to make DB to linear conversion by my own ... But it gone very wrong.. My ears almost exploded.
I was breaking my head for a solid hour or two around this trying to interpolate slider ratio to decibel value, I think godot cannot work with these long log numbers (or I'm too dumb to work with logs). Then I found your video and almost had a stroke when I saw that db_to_linear()... THANK YOU SO MUCH !!!
for my own knowledge is there something theoretically wrong with this ? :
var ratio = inverse_lerp( pow(10, min_db), pow(10, max_db), pow(10, target_db))
Excellent stuff! Do you also have a video on how to create a pause menu and an options screen? Also how do I make it so that my options remain when I restart the game?
Afraid not, but I'll keep those ideas in mind for the future. If you want options to persist, you'll have to look into saving your options data and loading it back in when you start the game up. For options, I like to keep it simple and use ConfigFile: docs.godotengine.org/en/stable/classes/class_configfile.html
im currently using File as my Config file like saving a Name Profile, by creating a new 'File.new()' the name will be persistent.. i also applied it to change the value of the Translation, where a user presssed English, it will create a new file called 'lang.cfg' and by using the lang it will keep the settings persistent... I dont know how to use the Config
off topic but how do you get you ready function to autofill with the void type. mine always autofills without a type and have to manually add it
Go to Editor Settings (under the Editor menu at the top of Godot) > Text Editor > Completion and check "Add type hints". Makes things so much better!
That and a few other editor setup items here if you're interested: shaggydev.com/2022/03/25/godot-code-editor-settings/
oh alright thanks a lot :D
@@TheShaggyDev thanks for this...
As someone who hasn't even touched audio yet in my game: How does godot handle having audio tracks set to sfx and master, or is the first one just always going to be everything regardless?
It's like any DAW/audio editor: you can create as many audio buses as you want, apply effects to each bus individually, send the audio from one bus to another, and in the end the Master receives the audio from all the buses. Godot's audio system is great.
I created a volume slider and modified the db linearly, which as you mentioned sucks. linear_to_db is the key here to not have your volume slider be terrible.
How do I fix the 9th and 10th line? It says "expected closing ")" after all arguments" and I typed it exactly like you did
That error means there's a missing ")" somewhere. Double check your code that you've got the same number of "(" as ")" and possibly check the code from my site or GitHub (both linked in the description) to double check everything.
good
yeah but how do i have the slider in a menu but change the volume on the game scene but having the slider in a different scene
Audio buses are global, so the volume can be controlled from anywhere in the application and all audio in the game will respect the changes in volume.
If you're asking about how to make an options menu, or something like that, afraid that's out of the scope of this video.
for some reason, on line 10 "value_changed.connect()" is not working for me. It says "not declared in the current Scope".
if the HSlider isn't the root node, then you need to specify the path, right before ".value_changed.connect()"
Line 9:Identifier "bus_value_changed" not declared in the current scope.
Hmm, going to need a little bit more to help you, but sounds like a function hasn't been declared somewhere?
How about a tutorial on key bindings/input remapping in Godot 4?
Not a bad suggestion! I'll keep that in mind as I plan out future videos.
How can you adjust audio using animation player?
I'm not sure there's a straightforward way to do that. A tween could do it since you could throw the volume code in a method and use the `tween_method` call, so maybe you could sync the two together in some way?
Hi, I can't able to customise the sliders, I used flatbox in style to customise but it didn't work only I can change grabber by using own texture, but slider is working fine thanks to this tutorial ❤
Any solution?
If the issue is that you can't see the bar when using a flat stylebox, try increasing the Content Margins of it. The sliders on their own don't have any width to show, but setting the Content Margins will allow you to pad things out enough to see.
@@TheShaggyDev Yes exactly, I can't see the bar when using flat stylebox, I will try this tomorrow, and thanks for instant reply 👍
Can you do this without making a separate scene just for the slider and without making a script just for the slider? Can't you just connect it to another script and handle it all in that function and how?
Sure. In that case, the code will be largely the same, you'll just need to use a reference to your slider to get the slider value and set up signal connections. Something like "my_slider.value = linear_to_db(...)" or "my_slider.value_changed.connect(...)"
bro it has errors pls help
May want to check your code against the sample project and double check everything. If you're still having problems, share the error here and I can try and take a stab at it.
@@TheShaggyDev i made it work bro, thanks for ur help i joined my first game jam and thanks to u
@@definitelynotje That's awesome! Good luck!!
talked and talked, but said nothing
i have a problem which i cant solve when i use a linear_to_db(AudioServer.get_bus_volume_db(music_bus_i)) its returning NaN or -inf (music_bus_i is just a variable storing index of music bus)