 This tutorial was brought to you by my patrons. Thank you so much for your support. Hello there! In this video, let's make an audio library. A note that you can use as a collection of audio samples, and the final result will look like this. You can tell it to play a random effect or you can tell it to play a specific effect. And also, as you can see, you can nest the audio libraries together. By the way, as you can see, I am using the pop label of the previous video for this visual feedback. So check out the card on the screen to see how you can make this pop label. So let's get started. So the first thing that you have to do is to create a note that will match the sound effect that you will use. So if it is a 3D sound effect, you can use spatial. If it is just a UI sound effect, you can use the simple note. Or if you use a 2D sound effect like for panning or that kind of effect, you can use a note 2D. So in my case, I will use a note 2D. I will name this for sound effect. The next thing that you want to do is to add a note that will correspond to the kind of library you want to make. So in my case, it will be sample 2D, audio stream sample 2D. So if you are doing a 3D audio library, you will use the audio stream player 3D. If you are doing for UI or other kind of effect, you can use the audio stream player. But I will use the audio stream player 2D. And you will rename it as you want to call the sound effect. So in my case, for instance, let's call this hike down. I will use just hike down. Then you want to drag and drop the source file. So hike down in my case. Or you can also make an audio stream random pitch. So for doing this, you will go to the create new resource button here. Search for audio random pitch. Audio stream random pitch. You create a new one here. For the audio stream, you drag and drop the source file. So either an odg or wave file. And then you save it as a resource in your disk. And you can use this for your node here. So drag and drop the audio sample random pitch to this stream here. But in my case, I already have an audio library, which I can use a lot of audios from that. I will go to the merge from scene feature from Godot. And I will go to the digital audio sound effect that I have. I will select all of these and merge them by pressing OK here. So there we have it. A lot of sound effects here. And the idea now is that whenever you tell the sound effect to play something, it will either randomly pick one of these, or we can also pass a specific sound to play. So let's go to the script. So I will attach a script to it. I will call it audio library. Library create. And here in the audio library, we will make a simple function that by default, it will receive a null sound effect, but you can pass one to it. So if we have a sound effect, we will get the node with the sound effect and play it. This will make so that if you pass the file, the string with the name of the sound effect you want to play, so in this case would be hiked down. So it will go here in this node and play it. So this is the way you can do this. And if you don't pass the node that you want to play it, it will get a random one. So we will call this variable and we will go to random integer. The way random i works is that it will generate a huge integer number, which you can get the module of the actual total size that you want to get. So in this case, child count. So it will get the module of the amount of children that this node has. This is how you can get kind of like if you will try to make a random range between zero and get child count. But we want an integer number. So this is the way you can get this. And we will get get child C and play it. So this is it. This is as simple as it is. So if we do have a sound effect we want to get, we will get this children by its name and play it. If we don't have anything, so if we pass a, if you call this method and not pass this argument, we will get a random children. And to make sure that we always play this in a random way, we will generate another seed by calling the randomize function here. So now I will save this. Yeah, let me save this. And just so we can have just so we can test this, I will call the function like this first. So we'll have a random one. And you can see that we get random one each time. Or I can pass something like hike, hike down. And don't forget you have to pass the exact number of the children, right? So and it will always play this one. But the real cool thing about this setup, this architecture is that you can nest a lot of audio libraries together. So let's say we want to make an audio library with the lasers. I will create node 2D here. I'll call this lasers. And I will move all of these lasers as children. I will add an audio library to it as well. So it will have the same behavior as this one here. So I will make just a button so we can call this function of the play, display method from outside the class. So I will just add a button here. I will make this play lasers sound. And I will connect the bottom up signal to the sound effect play method, passing a string extra call argument. And I will tell this to be lasers, which is the audio library we want to get. And by doing so, whenever we press this button, we will go to the sound effects library, tell it to play lasers. And it will go to this audio library here and tell it to play anything. So it will play randomly any of these sounds here. So let's get started and test this. Yeah, it works. So this is it. Thank you so much for watching. I hope you enjoyed it. Keep developing and until the next time.