How do I get a hovered image in a widget to stop playing a sound before it plays another? Like, if I move the mouse over one picture and a fairly long sound clip plays. Then, when I move the mouse over another picture, the two sounds overlap. So how do I stop the first audio clip so the second one plays without being overlapped?
Depending on how you are calling the sound in the first place you can promote a variable of the sound in question off the return value and call “Stop Audio Component” before playing each sound. OnHovered-> IsValid? Get and plug the sound variable into it and run that at the beginning. On “IsValid” call the Stop Audio Component and then run the new sound. Set that same variable off the return value of the new sound so it updates the variable with each new sound. Off “IsNotValid” play your sound and set the variable again. You can check multiple variables of sounds on the IsValid? and stop multiple sounds I do believe as well.
…Which obviously didn’t work. Anything I’m missing from the above image?
I’ll try and set it up an example when I get back to my PC and send you a screenshot.
The “Music” variable is the same variable as the previous sound. Copied and pasted on the next line of logic so it merely overrides the sound stored previously and stops the audio component and vice versa.
This will only work if you “spawn” the sound and doesn’t work with “play” sound 2d as you wouldn’t be able to create a reference to stop the audio component with play sound 2d.
Additionally, and haven’t tested completely with this setup, but you may need to destroy the audio component as well if you don’t want it lingering around too long. Not too sure though. Some particle effects work in this manner. You may not see them and they are stopped, but they pile up and become a problem if you have many of them not being destroyed.
It works! All seven sounds play without overlapping one another now. Thanks for the help!