How to Stop a Sound Effect When Button Focus Is Lost?

I have three buttons that each play a different sound when they have focus. Problem is, I want to stop the sound when I go from a button to another, yet the sound of previous button overlaps with the new focused button. How can I fix it?

1 Like

Are you stopping the sound on mouse out?

I am not using mouse, I only use keyboards, up and down.

Ok, can you stop the sound on ‘focus lost’ then?

I do not know how to stop the sound. I’ve read that there should be a node called like “Stop” or “Stop Audio” but I didn’t manage to find it.

Make the sound with

then later


image

:slight_smile:

1 Like

Thanks for your reply. I didn’t realise I needed to get a variable to call “Stop”.

I made this mess, and I see nothing wrong with it. Yet, it doesn’t solve the problem. Sounds from previous button focus, overlap with new button focus sound. Any idea?

edit: I saw something wrong with it.

I think code can not go past “Set Timer By Event” since it technically loops forever. So I moved “Stop” nodes “SoundEffectOnFocus” custom event. Now it works perfectly. Still, I get errors after ending the simulation since sometimes I am trying to close a sound effect that was not spawned to begin with. Would that be a problem or am I okay?

1 Like

It’s best to get rid of none errors, if you can :slight_smile:

1 Like

Do you have any idea? I am not quite sure on how to use “On Focus Lost” and “On Focus Received” events. I tried to use them but I do not know how to assign them to a widget. If I could use those events everything would be much simpler. I am kind of having writer’s block right now.

edit: nvm got it. I used “is valid” function to check if a sound is playing.

You click the ‘on focus’ plus signs ( near the bottom of the page in the button details in layout ), to write code for when that happens.

The just play your sound when the button gets focus, and stop it when it loses focus

:slight_smile:

I do not have an option for that. Only “Clicked”, “Pressed”, “Hovered”, “Unhovered”, “Released”

Use hovered and unhovered then?

Nope. Only works for mouse

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.