How to Stop “Play Sound 2D” Blueprint
Use SpawnSound2D instead. This way you’ll receive a ref to the audioComponent. Now you can manually play and stop the sound as you please
@Featuriing its working
but can i do like this is it affect performance?
Can you show me on the BluePrint?
I would actually recommend to store a reference to your AudioComponent in a variable (“MyAudioComp” in the example).
This way you can stop the sound on EndOverlap and destroy the audio component. This way things are properly cleaned up.
You can btw. even use AudioComp->FadeIn and AudioComp->FadeOut to make the sound start and stop smoothly
@Featuriing How to use that please show it on Blueprint
The most elegant way in this case is to re-use the AudioComponent of your sound.
We are just creating a new one in case there is none existing yet. Then we FadeIn on beginOverlap. OnEndOverlap we are just fading out but keeping the sound alive to reuse it on the next BeginOverlap by fading in again.