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...

ความคิดเห็น • 52

  • @Astro_retired
    @Astro_retired 10 หลายเดือนก่อน +20

    Damn, this is what a tutorial is supposed to look like. Short, informative and useful. Good job!

  • @blendingsentinel4797
    @blendingsentinel4797 20 วันที่ผ่านมา +1

    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

  • @IcarusGravitas
    @IcarusGravitas 11 วันที่ผ่านมา

    On the next to last day of my first game jam. You are my HERO!

  • @Zyjin
    @Zyjin ปีที่แล้ว +8

    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!

    • @joelgomes1994
      @joelgomes1994 ปีที่แล้ว +1

      Me too, any video from him is pure gold.

    • @TheShaggyDev
      @TheShaggyDev  ปีที่แล้ว +4

      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.

    • @Zyjin
      @Zyjin ปีที่แล้ว

      @@TheShaggyDev Awesome, glad to hear ;), one step at a time like everything else!

  • @lxyacht
    @lxyacht หลายเดือนก่อน +1

    fantastic video. I very much appreciated the explanation for converting linear to db. Really handy information.

  • @itsmidge
    @itsmidge 4 หลายเดือนก่อน +1

    Very helpful, informative, and concise. Helped me do what I was trying to do quickly, thank you!

  • @brinley5642
    @brinley5642 7 หลายเดือนก่อน +1

    Great tutorial! Short and sweet and good quality

  • @MemasMaklas
    @MemasMaklas 6 หลายเดือนก่อน +1

    Great tutorial! Exactly what I need! Thank you!

  • @Failfer
    @Failfer 6 หลายเดือนก่อน +2

    Extrmely well done and informative thank you very much!

  • @simonsaysgray
    @simonsaysgray 8 หลายเดือนก่อน

    super video, thank you so much!

  • @SheepUndefined
    @SheepUndefined 11 หลายเดือนก่อน +2

    2:18
    Without is literally just how Discord handles it.

  • @sheepcommander_
    @sheepcommander_ 8 หลายเดือนก่อน

    THANK YOU

  • @notreallycow
    @notreallycow 8 หลายเดือนก่อน +1

    Thanks!!
    Firstly, I tried to make DB to linear conversion by my own ... But it gone very wrong.. My ears almost exploded.

  • @Cacapoulette
    @Cacapoulette 7 หลายเดือนก่อน

    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))

  • @Betegfos
    @Betegfos ปีที่แล้ว

    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?

    • @TheShaggyDev
      @TheShaggyDev  ปีที่แล้ว +2

      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

    • @wordsmithscans
      @wordsmithscans 10 หลายเดือนก่อน

      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

  • @mcaped
    @mcaped ปีที่แล้ว +2

    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

    • @TheShaggyDev
      @TheShaggyDev  ปีที่แล้ว +2

      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/

    • @mcaped
      @mcaped ปีที่แล้ว

      oh alright thanks a lot :D

    • @wordsmithscans
      @wordsmithscans 10 หลายเดือนก่อน

      @@TheShaggyDev thanks for this...

  • @Kio_Kurashi
    @Kio_Kurashi ปีที่แล้ว +1

    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?

    • @joelgomes1994
      @joelgomes1994 ปีที่แล้ว +1

      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.

  • @Sil0_
    @Sil0_ 10 หลายเดือนก่อน

    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.

  • @Kirbystarallies1
    @Kirbystarallies1 4 หลายเดือนก่อน

    How do I fix the 9th and 10th line? It says "expected closing ")" after all arguments" and I typed it exactly like you did

    • @TheShaggyDev
      @TheShaggyDev  4 หลายเดือนก่อน

      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.

  • @barbodrz8645
    @barbodrz8645 2 หลายเดือนก่อน

    good

  • @zenzo4506
    @zenzo4506 5 หลายเดือนก่อน

    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

    • @TheShaggyDev
      @TheShaggyDev  5 หลายเดือนก่อน

      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.

  • @superguerrerodragon
    @superguerrerodragon 10 วันที่ผ่านมา

    for some reason, on line 10 "value_changed.connect()" is not working for me. It says "not declared in the current Scope".

    • @XolarisYT
      @XolarisYT 9 วันที่ผ่านมา

      if the HSlider isn't the root node, then you need to specify the path, right before ".value_changed.connect()"

  • @odachi4000
    @odachi4000 6 หลายเดือนก่อน

    Line 9:Identifier "bus_value_changed" not declared in the current scope.

    • @TheShaggyDev
      @TheShaggyDev  6 หลายเดือนก่อน

      Hmm, going to need a little bit more to help you, but sounds like a function hasn't been declared somewhere?

  • @FaeKitty
    @FaeKitty 7 หลายเดือนก่อน

    How about a tutorial on key bindings/input remapping in Godot 4?

    • @TheShaggyDev
      @TheShaggyDev  7 หลายเดือนก่อน

      Not a bad suggestion! I'll keep that in mind as I plan out future videos.

  • @kzuuuukyuu9317
    @kzuuuukyuu9317 2 หลายเดือนก่อน

    How can you adjust audio using animation player?

    • @TheShaggyDev
      @TheShaggyDev  2 หลายเดือนก่อน

      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?

  • @fictionalaudio
    @fictionalaudio 4 หลายเดือนก่อน

    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 ❤

    • @fictionalaudio
      @fictionalaudio 4 หลายเดือนก่อน

      Any solution?

    • @TheShaggyDev
      @TheShaggyDev  4 หลายเดือนก่อน

      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.

    • @fictionalaudio
      @fictionalaudio 4 หลายเดือนก่อน +1

      @@TheShaggyDev Yes exactly, I can't see the bar when using flat stylebox, I will try this tomorrow, and thanks for instant reply 👍

  • @emptydeletions
    @emptydeletions 10 หลายเดือนก่อน

    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?

    • @TheShaggyDev
      @TheShaggyDev  10 หลายเดือนก่อน

      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(...)"

  • @definitelynotje
    @definitelynotje หลายเดือนก่อน

    bro it has errors pls help

    • @TheShaggyDev
      @TheShaggyDev  หลายเดือนก่อน

      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.

    • @definitelynotje
      @definitelynotje หลายเดือนก่อน

      @@TheShaggyDev i made it work bro, thanks for ur help i joined my first game jam and thanks to u

    • @TheShaggyDev
      @TheShaggyDev  หลายเดือนก่อน

      @@definitelynotje That's awesome! Good luck!!

  • @saumonmeme7951
    @saumonmeme7951 หลายเดือนก่อน

    talked and talked, but said nothing

  • @rybomen_
    @rybomen_ 3 หลายเดือนก่อน

    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)