Organize Sound In Godot 4

Поділитися
Вставка
  • Опубліковано 3 лис 2024

КОМЕНТАРІ • 44

  • @joshhoffman7811
    @joshhoffman7811 8 місяців тому +6

    Your introduction to these concepts is fantastic. This is exactly what I was looking for, thank you for putting this video together! :)

    • @cadoink
      @cadoink  8 місяців тому

      Thank you so much! I'm glad you enjoyed it! :)

  • @crabirl
    @crabirl 7 місяців тому +3

    You mentioned having a signal dictionary between the classes around 9:10 -- I would love to know more about that.
    Thank you!

    • @cadoink
      @cadoink  7 місяців тому

      I kind of flubbed my word there. I was trying to say a single dictionary. 😅 What I meant was that instead of having a Dictionary for SoundQueues and a Dictionary for SoundPools, they could each implement a C# interface that defines a Play method. Then you could store both the queues and pools in one dictionary.

  • @baumwolle2548
    @baumwolle2548 Рік тому +21

    Nice one! Since good Godot projects depend on strong software architecture its awesome you shared your work

    • @cadoink
      @cadoink  Рік тому +3

      Thank you! I'm always looking for better ways to organize my code. :) I've gotten a lot of reuse with these structures over various game jams, so I hope they'll be useful for others.

  • @felbecker
    @felbecker Рік тому +7

    Thank you for putting time into this tutorial!
    Going further, one could think about implementing a priority system. The game should be able to prioritize sounds if there are too many. For instance, the fire sound from the player should have very high priority, whereas the same sound but from an enemy could be silenced if there are too many of them. I think this will require a small rewriting of you current SoundQueue approach.

    • @cadoink
      @cadoink  Рік тому

      That is a very interesting idea! I wonder if something like that could be achieved with a priority queue. I haven't run into this requirement before, but it would be fun to try and figure out.

  • @eeek143
    @eeek143 Рік тому +3

    I love seeing people talk more about audio aspect of things, excellent video

  • @gnastygames
    @gnastygames Рік тому +1

    nice vid, I had actually been thinking about this recently for my own game but hadn't searched anything about it.
    Seems very random for this to come up in my youtube home page 24 minutes after upload lmao

    • @cadoink
      @cadoink  Рік тому

      Serendipity! Hope its helpful! Let me know if it works out, or if you come up with some other cool ways of organizing sound. :)

  • @petersonnormil6799
    @petersonnormil6799 Рік тому

    awesome video for godot! it honestly taught me some things that I've never even tried in Unity. thanks so much!

  • @goodxp
    @goodxp 3 місяці тому

    very nice and informative video. thank you very much!

  • @tastedaspear7948
    @tastedaspear7948 8 місяців тому

    gr8 video mr.KING-GAMEDEV!

  • @moose6459
    @moose6459 11 місяців тому +6

    The SoundQueue isn't necessary. AudioStreamPlayer has a MaxPolyphony which does the same thing, allowing a sound to be played again while already playing if set higher than 1.

    • @cadoink
      @cadoink  10 місяців тому +1

      I either came up with this before MaxPolyphony was implemented (maybe an older version of 3.X), or before I learned about this. Thanks for the tip!

    • @E62147
      @E62147 7 місяців тому +1

      But then SoundPool isnt't necessary either, If I can use AudioStreamRandomizer? Im getting lost what is the best aproch to implement sound system.

    • @cadoink
      @cadoink  7 місяців тому

      @@E62147 So this looks to be a new feature of Godot 4. Its not a node, but a selection for the Stream on AudioStreamPlayer. This stream setting has a Streams property where you can add multiple streams. Pretty cool!
      My recommendation would be to use this in your Godot 4 projects and see if it meets your needs. You can also implement my solution if there is some specific behavior you want that the new Godot 4 option doesn't provide.

  • @sporktank
    @sporktank Рік тому

    Great video! Very nice way of solving these audio issues. Thanks for all the tips! 😄

    • @cadoink
      @cadoink  Рік тому

      Hope its useful! Its been great for the game jam projects. I typically stuff everything in the Sound Manager so I can quickly validate that everything is on the right audio buses for my sound settings. Perhaps an abuse of the singleton pattern, but acceptable for jams.😅

    • @sporktank
      @sporktank Рік тому

      @@cadoink Everything is acceptable in a jam. 😂

  • @moose6459
    @moose6459 11 місяців тому

    I ended up converting it all into a singleton with a PlaySound(Node3D owner, AudioData data) and PlayRandomSound(Node3D owner, IEnumerable). My AudioData is just a resource containing the stream and all the stream variables. Then I check in the singleton if the dictionary of sounds already contains an active AudioStream playing the sound, in which case I replay the sound, otherwise I create a new AudioStream child. This way all my active audio in the game is in one central location and any script can request to play a sound.

  • @andres_mpr
    @andres_mpr Рік тому

    This was amazing... I like mi code well structured and this is awesome, thanks

  • @DrZ_5000
    @DrZ_5000 4 місяці тому

    Great Tutorial, thx a lot! liked&subbed :)
    You have a nice way of explaining the software design behind your ideas. Good to see you using C#, I just started godot and prefer static typed languages. I will try this out in in my project for sure. Would it be possible, that you push that specific code in a minimal Godot project to github? Maybe that way people (including me) can collaborate and share their ideas about this topic there. We could also copy&paste the code more easily ;)
    cheers mate

    • @cadoink
      @cadoink  3 місяці тому

      Thank you for the kind words! I am glad you found the video useful. I've had a busy time with life stuff lately and would like to get back to UA-cam soon! When I do, I'd like to begin putting the code on GitHub for people to reference.

  • @0HHC
    @0HHC Рік тому +10

    Thank you!
    But can't you just increase max_polyphony in godot 4 for a queue?

    • @cadoink
      @cadoink  Рік тому +3

      I don't know! I've only recently started messing around with Godot 4. While I used Godot 4 for this video, I had typically been using these in Godot 3.5. Its possible that Godot 4 already solves queueing natively. I'll have to investigate! Thanks for the heads up!

    • @fkeyzuwu
      @fkeyzuwu Рік тому +3

      @@cadoink yeah im pretty sure they have polyphony for this in godot 4. still a nice video tho!
      also, instead of having the audiostreamplayer as a child shenanigans and having to check for errors, you could just add an @export variable for the audio file you want to play and when you add new audiostreamplayers you just set their audio file to the one you put inside the variable. that saves a bunch of code that seems kinda messy and unneeded imo.

    • @cadoink
      @cadoink  Рік тому +1

      @@fkeyzuwu Hadn't thought to use an export to get the audio stream and just create the audio stream players in the ready method. That's a great idea! Thanks for the suggestion!

    • @cadoink
      @cadoink  Рік тому +2

      @@fkeyzuwu One upside to my approach is that you can tweak the AudioStreamPlayer for particular sound effects if you need to adjust the db, the bus you want to use, or some other setting (especially spatial audio). This could also be achieved with exports passing these values through though.

  • @regen-Q
    @regen-Q 5 місяців тому +1

    from what i understand, increasing the max polyphony attribute of an AudioStreamPlayer node achieves the same result as your SoundQueue system. is there a particular reason why you chose this system over simply increasing the max polyphony?

  • @sziklamester1244
    @sziklamester1244 10 місяців тому

    Actually I created a simple menu for my game but actually the game is a single image and now not that matters. I managed from another video tutorial to play a music by using a music controller and autoload which is nice because I wanted the music works on the main menu and the options menu but actually not want to use it on the game scene. I only have currently one music to play but later when I start to build up my game I want to play different sounds and musics but now I would want to mute the music when I start my game scene.
    Actually what you shown in the video is good but I did not followed because not want to mess it up more than what may I did currently. Already used 3 peoples tutorial and mixed into one but not managed to fix this yet.
    I am using Godot 4.2 right now and currently none of the 7 tutorial I watched for helped me that much because they have had already a game or was just a mess.

  • @matiturock
    @matiturock Рік тому +1

    Hello excellent video. One suggestion is to please make the editor code letters bigger. Thank you.

    • @cadoink
      @cadoink  Рік тому

      Thank you for the suggestion. I'll increase the font size in future videos. :)

  • @FPTGOG
    @FPTGOG 10 місяців тому

    It says that "playback can only happen when a node is inside the scene tree", i can't use Sound Queue at all

    • @cadoink
      @cadoink  10 місяців тому

      You will need your SoundQueue somewhere in the scene tree. This could either be a part of a singleton that is autoloaded, for example a sound manager to manage all your sounds, or you can use these SoundQueue directly in the scenes that needs the sound, like a Player scene could have a SoundQueue for its footsteps sounds.

  • @juan_jojos
    @juan_jojos 11 місяців тому

    How to prevent from playing the sound pool every frame? wait until the current sound ends?

    • @cadoink
      @cadoink  11 місяців тому +1

      You should play the audio when the event happens. So when the player presses jump, or is hit by a projectile, etc. If you play the audio on the frame something happens, it shouldn't restart on other frames.
      Sometimes an event may occur very frequently. In those causes you may want to limit how many times a sound can be played. The size of your queue of sounds and how long they play can limit how frequently the sound will occur, so for some events it may skip playing the sound so that its not overwhelming.

  • @tastedaspear7948
    @tastedaspear7948 8 місяців тому

    btw, is it possible for me the to get my hands on that fireball png?

    • @cadoink
      @cadoink  8 місяців тому

      Its from the Kenny Micro Roguelike spritesheet: www.kenney.nl/assets/micro-roguelike

  • @DibyoshreeSarkar
    @DibyoshreeSarkar 11 місяців тому

    Okay so I have a bunch of sounds that I want to play, based on a dialogue script, What I did was set a new stream to the same audio player at runtime, so that when the script says "play a pop sound" the code looks in the asset library for a pop sound and sets the stream of the audio player to that sound.
    This works fine for a small project, but I was wondering if this is too inefficient for a larger project ?

    • @cadoink
      @cadoink  11 місяців тому

      I'm not entirely sure, but I think the resource stream is the expensive part. Once its loaded, creating and destroy AudioStreamPlayers should be efficient.