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 RU-vid soon! When I do, I'd like to begin putting the code on GitHub for people to reference.
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?
9:30 U can tween even easier by tweening the parameter directly like this: tween.TweenProperty(shaderMaterial, "shader_parameter/color", color1, color2, 5.0f); To get the correct path, u can just right-click the parameter in the editor -> "Copy Property Path"
Hey, I'm new to shaders and was wondering why WORLD_MATRIX and SMOOTHNESS aren't options, and throw errors? I changed smoothness to ROUGHNESS and both work, though. Then, as you changed your code, smoothness (lowercase) worked there. The only thing not working by the end was CAMERA_MATRIX but changed to PROJECTION_MATRIX and it works! Really cool effect and good intro to shader basics! Thank you for the tutorial :)
Are you using Godot 4? In this video I am using Godot 3. Some of the shader variables were renamed in Godot 4, so you'll need to do some googling to find alternatives. I believe the WORLD_MATRIX for example is now called MODEL_MATRIX. Sounds like you got it working regardless! Glad to hear. :)
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.
Awesome tutorial, helps me a lot to organize my sounds in the project. I found that the AudioStreamRandomizer exists and does a similar job to SoundPool, do you think the SoundPool is no longer needed anymore ?
What I typically do is I have a main scene that contains two children, the scene with the button, and the cutout scene. The scene with the button will have an event that the main scene will listen for. When that event fires, the main scene will receive the event and tell the cutout scene to play the animation. I'll also typically have events for when the animations finish. So once the screen is completely black, I can clear out my scene with a button (typically my main menu), and add whatever scene I want to transition to. Then I call the cutout scene to fade back in.
I like to keep a static class of settings that any scene can reference to get the volume settings. An alternative could be to create an autoloaded script where you store the settings.
@@cadoink Hey! Could you please explain the alternative? I've been trying, but when i try to change the slider value with the ready() function it just doesn't do anything... doesn't even return any errors
@@ricardopereira2390 The alternative meaning using an autoloaded script? This script would just contain settings values, then your UI component containing the slider would ask the autoloaded script what the setting should be and then set the value of the slider. This doesn't solve persistence, so each time you run the game it would use whatever the default value of the property on the autoloaded script is. If you want changes in values to persist you'll need to serialize them to disk, and deserialize from disk when you run your game.
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.
I ended up converting it all into a singleton with a PlaySound(Node3D owner, AudioData data) and PlayRandomSound(Node3D owner, IEnumerable<AudioData>). 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.
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.
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.
I'm confused as to why your shader overlays atop not only the background but the coral and other decorations when you only applied the material to your backdrop node. I'd like to achieve a similar effect but applied over every mesh in my scene (as though I were projecting the noise over the 3d space) but for me this just seems to apply flatly to just my terrain.
All the objects in my scene share the same material. I often use a single texture with a grid of colors as my albedo, and move the objects UV map to the color I want. I like to do this to keep the number of materials I use low.
How would you do this for an Area2D Node with C#? I have a player character that can pick up a power up to dash, and I want it to have a 50% opacity white color while the power up is going. I can create the Shader just fine with uniforms, but I don't know how to access the Shader properly with code. "Material as ShaderMaterial" is something I came across, but when I a set a new shader material to it, I can't SetShaderParameter as the object reference keeps returning null, which means I'm grabbing the wrong thing or the wrong way. Any insight is appreciated. SOLVED EDIT: Figured it out. I'm just incredibly green to this and was not getting the reference from the right node. My script was on the Area2D node, but it was my AnimatedSprite2D that I needed to get a reference to, which was a child of this node. Since the Area2D had no material, of course it would be null; I'm still getting used to the idea of needing references despite things appearing connected in the scene list. May be a teachable moment.
very nice! idea for extending this: SoundQueue is renamed SoundGroup. SoundGroup can play children of type: AudioSteam, SoundPool, or SoundGroup. SoundGroup has a checkbox for 'play simultaneously'. When not ticked, SoundGroup works as the sound queue currently does. When ticked, all child Playables play simultaneously. This allows playback of layering sounds from a single sfx play call, where each layered part can be randomly selected from a set of sound variations for extra richness. Sound nodes can be nested arbitrarily deeply for complex variation schemes.
When I try this in Godot v4.0.2 the sampler2d texture repeats at scales less than 1.0, even when I use repeat_disable in the shader uniform. Is this a recent bug, or am I missing something? UPDATE: I've tried this in 4.0.3-rc1 and it works as expected. It seems 4.0.2 had a bug and it has been resolved.
Hey. I just signed up. I have a doubt, if I use what you teach in your tutorials, the codes and shaders, I can use it in my projects freely, do I need to give credits? And is it free for commercial use?
Hello! You do not need to give me credit to use this in your project! You can use my shader code and/or my C# code from any of my videos for personal or commercial use without any attribution. I try to use only CC0 resources when I am working on tutorials or my own personal projects. The Fresnel function I use in this video comes from godotshaders.com, which requires uploaders to license their code/resources with with CC0, MIT or GNU GPL v.3. (see here godotshaders.com/license/)
@@cadoink Happy to help. Sometime we need to switch from different shaders, or make a tween animation. And there are lots of shader you can find all over the internet, but how to use them properly is the problem. Like I got a water shader, how could I put a water pit in my Top-Down game, when character walk though it, it will show waves and reflection. There are really few tutorials that talking about it.
@@WeirdGoat Finally got some time to make a video about interacting with shaders and materials using .NET. I briefly cover a way to tween shader uniforms. ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-hHi11LVQbis.html&lc=UgwKnMY12akseUJhOUx4AaABAg I didn't cover waves and reflections for a character, but my suggestion would be to fake the effect rather than complicate the water shader. You could spawn a quad that has a water ripple texture under the character, or use particles. For the reflection, one common technique is to spawn a copy of the player or object upside down underneath the player with a material/shader that makes it look under water. There may some some tricks around using the water as a mask for that copy. Might look into it myself, could make a good video.
That's a great idea! Another thing I've seen that people can add is a button to quickly mute. I think I've typically seen this as a little speaker icon next to the volume that you can click to mute or unmute.
@@cadoink yeah that would make a nice addition aswell. i like the concept of having simple audio nodes like that that fit any project and are customizable. great work on this tutorial
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.
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.
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.😅
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