How To Add Sound Effects the RIGHT Way | Unity Tutorial

Ойындар

Show your Support & Get Exclusive Benefits on Patreon (Including Access to this project's Source Files + Code) - / sasquatchbgames
Join our Discord Community! - / discord
In this tutorial I'll show you how to add sound effects properly into your game in Unity.
We'll start by making an awesome sound manager, and then I'll show you how to you control different audio groups (sound FX, music, master) with sliders in your menu.
I cover a lot here, so we're going to make this fast!
Link to Download the FREE 2D Asset Pack seen in this tutorial:
veilofmaia.com/tutorial-asset...
---
In need of some Unity Assets? Using our affiliate link is a great way to support us. It's free, and we get a small cut that helps keep us up and running: assetstore.unity.com?aid=1100lwgBQ
---
ChipTone Link:
sfbgames.itch.io/chiptone
Credits-----------------------------------------------------
Credits for Logorithmic Graph Image:
salfordacoustics.co.uk/sound-...
Contents of This Video: ------------------------------------------
00:00 - Intro + Scene Setup
00:34 - Play Sound From Enemy Audio Source
02:03 - Play Sound From PlayClipAtPoint()
03:14 - Creating the Sound Manager
07:26 - Add Ability to Play Random Sound Effects
08:37 - Setting Up Audio Mixer
10:01 - Setting Up Volume Controls with Slider from Menu
13:04 - Correcting the Volume Control Functions
Who We Are-------------------------------------
If you're new to our channel, we're Brandon & Nikki from Sasquatch B Studios. We sold our house to start our game studio, and work full time on building our business and making our game, Veil of Maia.
Subscribe for NEW game dev videos every Monday & Thursday!
Wishlist our Games:
Wishlist Samurado on Steam! - store.steampowered.com/app/23...
Wishlist Veil of Maia! - store.steampowered.com/app/19...
Follow us on Twitter for regular updates!
/ sasquatchbgames
#unitytutorial #unity2d #unity3d

Пікірлер: 62

  • @iPaintSmallThings
    @iPaintSmallThings2 күн бұрын

    This was immensely helpful. Also, the way you made dividers in the hierarchy was one of those "why didn't I think of that??" things. Thanks a bunch!

  • @andrewpullins8817
    @andrewpullins88176 ай бұрын

    Probably the best Unity audio tutorial I have seen so far.

  • @nickfrancisci

    @nickfrancisci

    2 ай бұрын

    Agreed - so incredibly helpful!

  • @ComputerVirusXD
    @ComputerVirusXD3 ай бұрын

    I really appreciate you taking the time to not just show the solution to the problem and add a code snippet to copy. You show how it can be done, explain the code and even address problems / negative examples. This is perfect for learning. Thank you very much!

  • @ekekw930
    @ekekw930 Жыл бұрын

    I love these kind of managers! I have a 2D project template and each time I find a gem like this I work it in there. Thanks a lot!

  • @thenewaeon
    @thenewaeon Жыл бұрын

    I'm just getting started learning Unity and am about to add audio to my first solo project. I definitely would have fallen for the beginner's traps shown here. It really seems worthwhile to go the extra mile to avoid a buggy mess. Thanks for the solid info and great job on the tutorial!

  • @DieterSoost
    @DieterSoost7 ай бұрын

    I am very stunned ! The title "...the RIGHT WAY" is really not an exaggeration. Thank you for that ! FYI for other dev's: Works under 2023.3

  • @HanyElsafty-sn9oc
    @HanyElsafty-sn9oc4 ай бұрын

    This is the most efficient sound manager I've ever tried, you have my respect man!

  • @perssontm1628

    @perssontm1628

    4 ай бұрын

    You should combine this with codemonkeys soundmanager, it's the ultimate sound system

  • @adassus
    @adassus4 ай бұрын

    You really make the best tutorials!

  • @volkantansk816
    @volkantansk8163 ай бұрын

    You saved so much time of mine. Thanks a lot.

  • @catoise
    @catoise Жыл бұрын

    Thank you. Very helpful video!!

  • @hasanalkan8624
    @hasanalkan86245 ай бұрын

    This video made my job much easier. I decided to leave the sound part until last, along with a lot of prefabs. The only thing I will do now is to give all the sounds as variables to the soundFxManager and call those sounds from the prefabs. Otherwise I would have to add sounds to all of them one by one. thanks a lot.

  • @goragarxgamedev
    @goragarxgamedev2 ай бұрын

    Amazing tutorial :)

  • @Betruet
    @Betruet Жыл бұрын

    fantastic explanations

  • @Notreal76
    @Notreal76 Жыл бұрын

    Great Tutorial, as always.

  • @sasquatchbgames

    @sasquatchbgames

    Жыл бұрын

    Thanks again! 🙂

  • @francosoler1756
    @francosoler17564 ай бұрын

    Really cool tutorial, something i would change to avoid code repetition is to pick the random clip in the PlayRandomSound function but then call the original PlaySound function and pass the random audioclip

  • @mmokzlrsn
    @mmokzlrsn7 ай бұрын

    great video thank you thank you

  • @kidsseeghosts121
    @kidsseeghosts1215 ай бұрын

    You should make a guide on how to create that kind of pause menu!

  • @brendanwebster5138
    @brendanwebster51387 ай бұрын

    Great video. Just wondering if we should follow the same setup within the music manager such as using a prefab game object (i.e. "MusicObject) and make a singleton as well?

  • @its_nuked
    @its_nuked2 ай бұрын

    This is absolutetly fucking amazing. Thank you yo! You've saved our deadlined project by telling us how NOT to do it aswell, thats what I was thinking to do first xD

  • @ghy518
    @ghy5184 ай бұрын

    nice tutorials

  • @SamOnTehsea
    @SamOnTehsea6 ай бұрын

    The log10(level) * 20 is the aproximative real world formula to calculate the power of sound. So what is the value of X for x.pow(10) == level. Also that was a great tutorial, I will be using yous system in my current project.

  • @igo_s5717
    @igo_s57175 ай бұрын

    Thanks!

  • @sasquatchbgames

    @sasquatchbgames

    5 ай бұрын

    Thank you!

  • @demond2133
    @demond21333 ай бұрын

    This is a great solution for an audio manager however how might this implement a Stop() function? If say you had an audio sound that you wanted to stop mid sfx then how would you reference the audioSource? Say i have a light sound that plays when a light is active. When I turn off that light how do I make the sound stop with it?

  • @kidsseeghosts121
    @kidsseeghosts1215 ай бұрын

    what does it mean if I get and error in Unity that says "The name 'volume' does not exist in the current context?"

  • @kabejadev6333
    @kabejadev63332 ай бұрын

    Instead of instantiating and destroying the audio source, As we would still assign the audio clip we want, could object pooling be used and maybe as a precaution remove the clip from the audio source before returning source to pool?

  • @owencoopersfx
    @owencoopersfx Жыл бұрын

    Nicely done. All the most important points covered. Something I would add is that in addition to playing random clips, it’s nice also randomly setting the pitch and volume, which can give a sense that you have more asset variation. The issue then is that destroying by clip length will not adapt to the length change from pitch adjustment. To account for this, you can set the destroy time for the spawned AudioSource to: audioSource.clip.length/audioSource.pitch. Hope that helps!

  • @owencoopersfx

    @owencoopersfx

    Жыл бұрын

    I want to add: it’s cool seeing your journey. Glad you’re sharing it through KZread :) I do technical game audio professionally (full time - I’m not looking for money here), so I just thought I’d extend that if you run into audio issues with your game you can hit me up for some advice. Cheers and best of luck!

  • @ChapCanai
    @ChapCanai Жыл бұрын

    Do the sliders stop working after reloading scene?

  • @breadthegod7192
    @breadthegod719224 күн бұрын

    Do you know how to set it up to play an audio clip before playing a looping, continuous piece of music?

  • @ploomper4976
    @ploomper49762 ай бұрын

    Can I do this same thing but instead of creating my own sound clips array, use the built in Random Audio Container in unity? v helpful tutorial

  • @codaq4043
    @codaq404317 күн бұрын

    If there is a single sfx audio manager what would happen in the case of multiple sfx playing at the same time? Or is this a case were we wouldnt want to make a singleton

  • @Marcos69701
    @Marcos697012 ай бұрын

    Hey, you didn't show how to call the menu, nor how to make the sliders :(

  • @ekekw930
    @ekekw930 Жыл бұрын

    How can I make it so these settings persist using PlayerPrefs? I have added a save button and the values are stored correctly, in my GameManager's on Awake function I load these values, set them in the SoundMixerManager and also in my OptionsMenuUI to the sliders. The sliders continue to be full.

  • @ekekw930

    @ekekw930

    Жыл бұрын

    Fixed it by loading the values from PlayerPrefs in Start() instead of Awake(). :D

  • @midniteoilsoftware
    @midniteoilsoftware Жыл бұрын

    I've never seen anyone instantiate and destroy AudioSource objects like that. Each of my sound managers has a single audio source mapped to an audio mixer group and I use PlayOneShot() to play sound effects. Of course that doesn't use spatial audio though so if you really want the surround sound effect I guess you need an approach similar to yours. I would probably implement object pooling though so as not create a bunch of garbage and get lag spikes.

  • @sasquatchbgames

    @sasquatchbgames

    Жыл бұрын

    yea I was never able to find a solution that I was 100% happy with, so I made this one. PlayClipAtPoint has the spatial audio, but it uses Instantiate/Destroy with no way to change that as far as I can tell. PlayOneShot is great except for the spatial audio being a bit lacking. This way, you get the spatial audio, as well as the abillity to easily swap it into an object pooling system (and by extension, control your voice count fairly easily so you don't go above the threshold.)

  • @iiropeltonen

    @iiropeltonen

    Жыл бұрын

    ​@@sasquatchbgames Hey I wanted to share with you an implementation where you actually can add a mixergroup to an audiosource that is instantiated at runtime. I had this same problem so I managed to get this solution up and working. You need to put your mixer in the "Resources" folder. Then you can get a reference to it in script with _myMixer = Resources.Load("stringPath") as Audiomixer; (Example "Resources/Mixers/Mainmixer") THEN You can get a reference to the mixergroup by AudioMixerGroup _sfxGroup = _myMixer.FindMatchingGroups("stringName") THEN You can assign it to an audiosource at runtime by. _exampleAudioSource.outputAudioMixerGroup = _sfxGroup; AND now you can instantiate Audiosources at runtime while still having control of their mix!

  • @sasquatchbgames

    @sasquatchbgames

    Жыл бұрын

    @@iiropeltonen awesome man, thanks!

  • @TheProzonedCreeper

    @TheProzonedCreeper

    3 ай бұрын

    Object pooling was my first thought as well. Im debating implementing object pooling for this system, but I'm not sure if it's worth it in the project I'm working on because there would only ever be like 3 sound effects playing at once, but you never know if that'll change

  • @YoutuberUser002

    @YoutuberUser002

    3 ай бұрын

    WHATTT!? your stupid 😅

  • @truth5764
    @truth57645 ай бұрын

    Can this be used in 3D games too? Haven't tested it yet but I just wanna be sure

  • @Mikes-Code

    @Mikes-Code

    4 ай бұрын

    Of course, no difference. I use it in my 3D game.

  • @mustafa_unitydev
    @mustafa_unitydev11 ай бұрын

    What about saving the value of voiumes ?? These will be lost each time the scene reloads? or not?

  • @ThePoePoee

    @ThePoePoee

    10 ай бұрын

    did you find a solution? wondering the same thing

  • @mustafa_unitydev

    @mustafa_unitydev

    9 ай бұрын

    @@ThePoePoee playerprefs can be used I think

  • @kartof192

    @kartof192

    7 ай бұрын

    ​@@mustafa_unitydevyes use player prefs and save it as float or int

  • 4 ай бұрын

    Nice tuto, BUT, how to play a sound FX from a Button?

  • @Mikes-Code

    @Mikes-Code

    4 ай бұрын

    Every button has a onClick event in the inspector, add the SoundManager into it, and active the playSoundFX method. All of this can be done in the inspector, on the button component. Or you can add a reference for the button into a script and add a onClickListenter on it, then call the PlaySoundFX method this way.

  • @HardPlay-iv2fm
    @HardPlay-iv2fm25 күн бұрын

    Hello!!! Thank you for very cool tutor! But how can I save these values in PlayerPrefs and then load them afterwards, to save the settings? public AudioMixerGroup Mixer; private void Start() { GetComponentInChildren().value = PlayerPrefs.GetFloat("MusVolume", 1); GetComponentInChildren().value = PlayerPrefs.GetFloat("FxVolume", 1); } public void MusicVolume(float volume) { Mixer.audioMixer.SetFloat("MusicVolume", Mathf.Log10(volume) * 20f); PlayerPrefs.SetFloat("MusVolume", volume); } public void SFXVolume(float volume) { Mixer.audioMixer.SetFloat("SfxVolume", Mathf.Log10(volume) * 20f); PlayerPrefs.SetFloat("FxVolume", volume); }

  • @VEOdev
    @VEOdev3 ай бұрын

    Won't this cause performance issues? like you can't use object pooling her, looks like it will generate a lot of garbage collection since we keep destroy and respawn audio objects especially when you have multiple sounds for the same character.

  • @leo8292

    @leo8292

    2 ай бұрын

    Probably a good optimisation to add on top if you end up producing too much garbage. Remember, only optimize when it becomes an issue, focus on getting the game out

  • @carboncorvidswe
    @carboncorvidswe6 ай бұрын

    For me it doesn't create a soundFXObject in the inspector

  • @carboncorvidswe

    @carboncorvidswe

    6 ай бұрын

    under the script for the manager that is

  • @Coco-gg5vp
    @Coco-gg5vp Жыл бұрын

    First

Келесі