- Home /
How to prevent button audio from playing on scene load?
I have UI buttons that make noises when selected. Everything works as intended, but when I load my scene the button selection noise plays because the event system selects a default button, even when the user hasn’t tried selecting anything yet. Is there a way to prevent this? As far as I’m aware you need to assign a default button to the event system or none of your buttons will work. Also, is there a way to stop the mouse cursor from triggering these sounds? I’ve scripted away the ability for the mouse to trigger any button functionality, but it still makes the button selection sounds when clicked.
Are you following someone else's implementation? I ask that because it sounds like you don't actually know how it's making the sound. I would have to take a look at your implementation to know what is wrong.
I do know that you do not need to set up a default button for buttons to work, this also makes me think you are using another party's implementation. Buttons don't make sounds unless you code them to do so or set it up in their OnClick event in the inspector. If you can supply some code and screen shots I can help.
I usually just set up my buttons to have two OnClick events in the inspector. One for the sound by accessing an AudioSource and it's PlayOneShot() method and giving it a sound clip... then the other OnClick Event Points to the script that has a public void method that does whatever I want the button to do when it is pressed. Like I said, I don't know what you are doing yet so I can't help until I see it. But I would suggest understanding exactly the system you are using or you are going to be frustrated all the time.
Answer by tormentoarmagedoom · May 08, 2018 at 08:24 AM
Good day.
First, Where the Audiosource are? is one for all butons? or every button ahve a AudioSource?
I'm not 100% sure, but i think this is false : "you need to assign a default button to the event system or none of your buttons will work".
Anyway, you can modify the volume for example
AudioSource.volume = 0 ;
And activate it at the first Update frame (once everything has been initialized)
OTher thing is, did you check your audiosource? is the "Play on awake" activated? if it is... this is the problem!
Give feedback! Bye!
I have an “Audio$$anonymous$$anager” as my audio source, but each button has an event trigger attached to it that plays a sound when selected. Play On Awake is not selected.
Then if you have an audiomanager, just make the volume to be 0 at the start, and crea$$anonymous$$ if sentence iside update with
bool InitialVolumeSet = false;
void Update()
{
if (InitialVolumeSet == false && Input.any$$anonymous$$ey)
{
Change volume to normal value
InitialVolumeSet = true
}
}
OR something like this!
So you will prevent this initially sound!
Bye :D
I'm pretty sure, as well, that you do not need a default.
You are proposing a band-aid fix. The developer needs to post code and describe the actual set-up. As you pointed out, it doesn't seem like they set things up correctly.
Answer by Dalsia · May 08, 2018 at 05:10 PM
I appreciate most of your responses, but the answer was a lot simpler than we all thought. Instead of making my buttons play a noise when "selected," I had to make them play a noise when deselected using Unity's event trigger component. The UI selection sound no longer plays when starting a scene.
Your answer
![](https://koobas.hobune.stream/wayback/20220612162233im_/https://answers.unity.com/themes/thub/images/avi.jpg)