How to stop sound cue

Hi, I was wondering how do you stop a Sound cue? I know this is probably a really simple answer but all the Videos ive seen it either are outdated or don’t work. Basically I have a character that can do a sword spin in mid air and their is a sound effect with that, and when he lands I want the sound effect to immediately stop but I cant for the life of me figure it out. Any help would be appreciated. Thanks:)

Here’s a code snippet:

In .h file:

UPROPERTY(EditInstanceOnly)
    UAudioComponent* _audioComponent;

In .cpp file:

// play sound if it is not playing
if (_audioComponent->IsPlaying() == false)
{
	_audioComponent->Play();
}

// stop sound if sound is playing
if (_audioComponent != nullptr && _audioComponent->IsPlaying())
{
	_audioComponent->Stop();
}
2 Likes

Hey there @Justice-Pingu! Welcome to the community! So just like how Shmoopy referenced in C++, in blueprint it’s the same, all you have to do is get a reference to the audio component itself you’re using and then call the stop node on it.

Hi, thanks for the response. I tried this and it doesnt work, the sound still continues when I land. The sound cue in play isnt looping.
I put the stop at the end of the animation node but still doesnt work.
I originally put the stop at the end of my “when landed” node but i get an error message with that. Sorry im no good with coding right now as im still learning.


2 Likes

Was it resolved or was the solution mistakenly marked?

It’s best to store the return value of the CreateSound2D function (the AudioComponent) as a variable. It looks like you’re trying to perform operations directly on the return value, and once you’re outside of the immediate context of the function the audio component can no longer be found.

2 Likes

Exactly