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.
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.
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.
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.
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
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.
@@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.
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.😅
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.
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
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.
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!
@@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.
@@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!
@@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.
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?
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.
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.
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.
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 ?
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.
Your introduction to these concepts is fantastic. This is exactly what I was looking for, thank you for putting this video together! :)
Thank you so much! I'm glad you enjoyed it! :)
You mentioned having a signal dictionary between the classes around 9:10 -- I would love to know more about that.
Thank you!
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.
Nice one! Since good Godot projects depend on strong software architecture its awesome you shared your work
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.
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.
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.
I love seeing people talk more about audio aspect of things, excellent video
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
Serendipity! Hope its helpful! Let me know if it works out, or if you come up with some other cool ways of organizing sound. :)
awesome video for godot! it honestly taught me some things that I've never even tried in Unity. thanks so much!
very nice and informative video. thank you very much!
gr8 video mr.KING-GAMEDEV!
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.
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!
But then SoundPool isnt't necessary either, If I can use AudioStreamRandomizer? Im getting lost what is the best aproch to implement sound system.
@@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.
Great video! Very nice way of solving these audio issues. Thanks for all the tips! 😄
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.😅
@@cadoink Everything is acceptable in a jam. 😂
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.
This was amazing... I like mi code well structured and this is awesome, thanks
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
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.
Thank you!
But can't you just increase max_polyphony in godot 4 for a queue?
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!
@@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.
@@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!
@@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.
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?
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.
Hello excellent video. One suggestion is to please make the editor code letters bigger. Thank you.
Thank you for the suggestion. I'll increase the font size in future videos. :)
It says that "playback can only happen when a node is inside the scene tree", i can't use Sound Queue at all
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.
How to prevent from playing the sound pool every frame? wait until the current sound ends?
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.
btw, is it possible for me the to get my hands on that fireball png?
Its from the Kenny Micro Roguelike spritesheet: www.kenney.nl/assets/micro-roguelike
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 ?
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.