Probably the best Unity audio tutorial I have seen so far.
@nickfrancisci7 ай бұрын
Agreed - so incredibly helpful!
@ComputerVirusXD8 ай бұрын
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!
@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!
@ga7axy4 ай бұрын
I really appreciate how you write comments outlining what you’re going to do before writing the actual code. It clearly explains your thought process, and as a viewer, it couldn’t be more helpful. Thank you so much for this tutorial!
@Smile1oasis3 ай бұрын
rare W
@DieterSoost Жыл бұрын
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
@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!
@iPaintSmallThings4 ай бұрын
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!
@idkwhatimdoimg216515 күн бұрын
this shit so goated. Love having short instructions for different methods cause i can choose whichever one is more convenient depending on the project
@HanyElsafty-sn9oc8 ай бұрын
This is the most efficient sound manager I've ever tried, you have my respect man!
@perssontm16288 ай бұрын
You should combine this with codemonkeys soundmanager, it's the ultimate sound system
@francosoler17569 ай бұрын
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
@kidsseeghosts12110 ай бұрын
You should make a guide on how to create that kind of pause menu!
@ExpensivePizza2 ай бұрын
Sometimes it can be useful to keep your sliders going between 0 and 100 for displaying the volume as text or perhaps saving the volume level to player prefs. So rather than changing the numbers on the slider I wrote a couple of functions for converting between whole numbers (0 to 100) and the Log10 values and visa versa. private static float ValueToVolume(float value) { var normalized = value / 100f; var scaled = Mathf.Lerp(0.0001f, 1f, normalized); var volume = Mathf.Log10(scaled) * 20f; return volume; } private static float VolumeToValue(float volume) { var scaled = Mathf.Pow(10, volume / 20f); var normalized = Mathf.InverseLerp(0.0001f, 1f, scaled); var value = normalized * 100f; return value; }
@herocartcy36644 ай бұрын
OMG THANK YOU SOOOO MUCH I WAS SITTING ON THIS FOR 2 DAYS AND NOW I HAVE PUT SOUNDS AND SFX ON EVERYTHING THANKS TO THX SO MUCH!!!!!
@Outra20244 ай бұрын
you increased my confidence ngl
@hasanalkan862410 ай бұрын
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.
@Solenea1122 ай бұрын
This is by far the best tutorial I have followed! Thanks 😃
@karatepunk8 ай бұрын
You really make the best tutorials!
@fulgencejuniorlohore85422 күн бұрын
Thanks buddy! almost 2025 and still relevant!
@717pixels93 ай бұрын
There might be a lot of sounds and creating/destroying gameobjects is taxing, isn't it?
@Day7Studio3 ай бұрын
This tutorial is a godsend! Ty Sir!
@igo_s571710 ай бұрын
Thanks!
@sasquatchbgames10 ай бұрын
Thank you!
@volkantansk8168 ай бұрын
You saved so much time of mine. Thanks a lot.
@sgaming3174Ай бұрын
Thanks for the wonderful tutorial
@luanhii53054 ай бұрын
Thanks! This will be my video reference to create audio systems.
@kabejadev63337 ай бұрын
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?
@caradepeidoАй бұрын
yea. i hope this isn't considered treason, but @git-amend has a good tutorial on this if you still need it.
@SamOnTehsea11 ай бұрын
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.
@babdie4 ай бұрын
my dear good sir, Mathf.Log10(value) * 20f ..... where value ranges from 0 to -80 log(-ve numbers) is giving NaN output ..how's it working for you
@brendanwebster513811 ай бұрын
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?
@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 Жыл бұрын
I want to add: it’s cool seeing your journey. Glad you’re sharing it through KZbin :) 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!
@magnuskjr-jensen2972Ай бұрын
Banger tutorial man
@its_nuked7 ай бұрын
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
@gabscamps1Ай бұрын
it doesnt work, for some reason it only plays sounds when the audio that is linked to the object that i want to play sound is the same a the soundfxobject, if i try something different it will spawn a sfxobject in the scene but the audio wont play
@midniteoilsoftware2 жыл бұрын
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.
@sasquatchbgames2 жыл бұрын
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.)
@iiropeltonen2 жыл бұрын
@@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!
@sasquatchbgames2 жыл бұрын
@@iiropeltonen awesome man, thanks!
@TheProzonedCreeper8 ай бұрын
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
@znoppenАй бұрын
@@iiropeltonen I'm just finding this now, a year or so later. Could you explain how I integrate this into the tutorial? Also, I'm so far up to 7:24 and the Destroy() doesn't work for me, the cloned SoundFXObject stays.
@maxg5196Ай бұрын
I noticed that there was a delay though on the audio clip. I am having this issue too with my own project. I want the audio to immediately come in as it gives better feedback to the player. Do you know how to do this?
@catoise Жыл бұрын
Thank you. Very helpful video!!
@Notreal762 жыл бұрын
Great Tutorial, as always.
@sasquatchbgames2 жыл бұрын
Thanks again! 🙂
@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 Жыл бұрын
Fixed it by loading the values from PlayerPrefs in Start() instead of Awake(). :D
@IevgenBaziak24 күн бұрын
Clicked. Coded. Works.
@kuraudodev3 ай бұрын
what if you want to control the volume of individual sound effects in the mixer?
@davidebertoni7192 ай бұрын
Nice tutorial. I get this error: Some objects were not cleaned up when closing the scene. (Did you spawn new GameObjects from OnDestroy?) The following scene GameObjects were found: SoundFXObject(Clone) SoundFXObject(Clone) My code is the same a the tutorial, this error happens if i restart the scene every time. Any ideas on how to fix it?
@golden_harp9303Ай бұрын
thank you! great video
@goragarxgamedev7 ай бұрын
Amazing tutorial :)
@breadthegod71925 ай бұрын
Do you know how to set it up to play an audio clip before playing a looping, continuous piece of music?
@darkmatter64673 ай бұрын
What about using the UI Toolkit instead of the legacy UI elements?
@DerpyEinstein2 ай бұрын
Thanks for the help!
@demond21338 ай бұрын
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?
@kidsseeghosts12110 ай бұрын
what does it mean if I get and error in Unity that says "The name 'volume' does not exist in the current context?"
@Betruet Жыл бұрын
fantastic explanations
@codaq40435 ай бұрын
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
@ploomper49766 ай бұрын
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
@oyleolduboyleoldu36775 күн бұрын
How does it sound like: Create a script with all functions and clips inside like die() respawn() etc add it to a empty gameobject than access to it through that gameobject with find methor or manualy adding your enemy object player object etc that was first thing in my mind
@patek23853 ай бұрын
sure, but what if sound is continuous and needs to follow the source?
@Marcos697017 ай бұрын
Hey, you didn't show how to call the menu, nor how to make the sliders :(
@mmokzlrsn Жыл бұрын
great video thank you thank you
@babdie4 ай бұрын
wait so if I have 20 coins at a place in my game and i collect them ..i will have to spawn 20 audiosources ?
@Outra20244 ай бұрын
yes
@mustafa_unitydev Жыл бұрын
What about saving the value of voiumes ?? These will be lost each time the scene reloads? or not?
@ThePoePoee Жыл бұрын
did you find a solution? wondering the same thing
@mustafa_unitydev Жыл бұрын
@@ThePoePoee playerprefs can be used I think
@kartof19211 ай бұрын
@@mustafa_unitydevyes use player prefs and save it as float or int
@Bokaley2 ай бұрын
audioSource.pitch = (float)Random.Range(8, 12) / 10; Good way to randomize your sound if you only have one
@truth576410 ай бұрын
Can this be used in 3D games too? Haven't tested it yet but I just wanna be sure
@Mikes-Code8 ай бұрын
Of course, no difference. I use it in my 3D game.
@ChapCanai Жыл бұрын
Do the sliders stop working after reloading scene?
@Outra20244 ай бұрын
yes
@HardPlay-iv2fm5 ай бұрын
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); }
@VEOdev8 ай бұрын
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.
@leo82927 ай бұрын
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
@ghy5189 ай бұрын
nice tutorials
9 ай бұрын
Nice tuto, BUT, how to play a sound FX from a Button?
@Mikes-Code8 ай бұрын
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.
@carboncorvidswe10 ай бұрын
For me it doesn't create a soundFXObject in the inspector