No video

Organize Sound In Godot 4

  Рет қаралды 14,928

Cadoink

Cadoink

Жыл бұрын

A tutorial about different way to organize sound effects in Godot 4 (concepts all apply to Godot 3.X as well!). In this video, I will talk about three techniques I use to organize my sound: SoundQueues, SoundPools, and the SoundManager.
These structures can be used to organize sounds, prevent sounds from being cut off, and playing random similar sound effects (good for things like footsteps).
All examples are using C#, but you can create the same structures using GDScript or any other language.
Let me know in the comments how you structure your sound in your game dev projects!
🎨 Assets used in the video:
Kenney - www.kenney.nl/...
www.kenney.nl/...
www.kenney.nl/...
🎵 Music:
Silent Wood by Purrple Cat | purrplecat.com/
Music promoted by www.chosic.com...
Creative Commons CC BY-SA 3.0
creativecommon...

Пікірлер: 44
@joshhoffman7811
@joshhoffman7811 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 5 ай бұрын
Thank you so much! I'm glad you enjoyed it! :)
@baumwolle2548
@baumwolle2548 Жыл бұрын
Nice one! Since good Godot projects depend on strong software architecture its awesome you shared your work
@cadoink
@cadoink Жыл бұрын
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 Жыл бұрын
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 Жыл бұрын
I love seeing people talk more about audio aspect of things, excellent video
@crabirl
@crabirl 5 ай бұрын
You mentioned having a signal dictionary between the classes around 9:10 -- I would love to know more about that. Thank you!
@cadoink
@cadoink 5 ай бұрын
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.
@goodxp
@goodxp 22 күн бұрын
very nice and informative video. thank you very much!
@projectavalongame
@projectavalongame Жыл бұрын
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. :)
@tastedaspear7948
@tastedaspear7948 5 ай бұрын
gr8 video mr.KING-GAMEDEV!
@petersonnormil6799
@petersonnormil6799 Жыл бұрын
awesome video for godot! it honestly taught me some things that I've never even tried in Unity. thanks so much!
@andres_mpr
@andres_mpr Жыл бұрын
This was amazing... I like mi code well structured and this is awesome, thanks
@0HHC
@0HHC Жыл бұрын
Thank you! But can't you just increase max_polyphony in godot 4 for a queue?
@cadoink
@cadoink Жыл бұрын
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 Жыл бұрын
@@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 Жыл бұрын
@@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 Жыл бұрын
@@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.
@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 8 ай бұрын
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 7 ай бұрын
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 4 ай бұрын
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 4 ай бұрын
@@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.
@DrZ_5000
@DrZ_5000 Ай бұрын
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 29 күн бұрын
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 KZfaq soon! When I do, I'd like to begin putting the code on GitHub for people to reference.
@moose6459
@moose6459 8 ай бұрын
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.
@regen-Q
@regen-Q 2 ай бұрын
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?
@matiturock
@matiturock Жыл бұрын
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. :)
@sziklamester1244
@sziklamester1244 7 ай бұрын
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.
@FPTGOG
@FPTGOG 7 ай бұрын
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 7 ай бұрын
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.
@tastedaspear7948
@tastedaspear7948 5 ай бұрын
btw, is it possible for me the to get my hands on that fireball png?
@cadoink
@cadoink 5 ай бұрын
Its from the Kenny Micro Roguelike spritesheet: www.kenney.nl/assets/micro-roguelike
@DibyoshreeSarkar
@DibyoshreeSarkar 9 ай бұрын
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 8 ай бұрын
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.
@juanjosepenabecerra7746
@juanjosepenabecerra7746 8 ай бұрын
How to prevent from playing the sound pool every frame? wait until the current sound ends?
@cadoink
@cadoink 8 ай бұрын
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.
Control SFX and Music in Godot - Godot Fundamentals
15:45
Game Dev Artisan
Рет қаралды 23 М.
Easy & efficient global SFX in Godot 4
5:28
Retrobright
Рет қаралды 7 М.
SPILLED CHOCKY MILK PRANK ON BROTHER 😂 #shorts
00:12
Savage Vlogs
Рет қаралды 44 МЛН
Joker can't swim!#joker #shorts
00:46
Untitled Joker
Рет қаралды 38 МЛН
Cutout Transition Effect in Godot
4:29
Cadoink
Рет қаралды 3,8 М.
Fake Water Caustics Shader in Godot. GLES2 Compatible!
5:39
Cadoink
Рет қаралды 3,8 М.
Volume Settings Tutorial For Godot 4
14:26
Cadoink
Рет қаралды 2,2 М.
Interacting With Godot Materials And Shaders Using C#
10:34
Cadoink
Рет қаралды 1,9 М.
Bubble Tutorial in Godot
5:08
Cadoink
Рет қаралды 1,1 М.
A Symmetric Escape - Godot Release Spotlight
2:50
Cadoink
Рет қаралды 279
SPILLED CHOCKY MILK PRANK ON BROTHER 😂 #shorts
00:12
Savage Vlogs
Рет қаралды 44 МЛН