Any answer that is posted with Blueprint screenshots or referencing Blueprint solutions will be downvoted.
C++ Answers Only!
I understand how to simply play a sound:
UGameplayStatics::PlaySound2D(owner, sound_cue_reference, 1.0f, 1.0f, 0.0f);
How do you stop a sound?
How do you tell if a sound is currently playing?
Thank you in advance.
1 Like
Any answer to this question?
billnc
(billnc)
November 2, 2018, 7:18pm
3
You will need to use an AudioComponent. PlaySound2D is a fire and forget. You cannot stop it from playing. Use an AudioComponent instead.
UAudioComponent::Play()
UAudioComponent::IsPlaying()
UAudioComponent::Stop();
Actually, I found an answer to this question myself on some back water thread on another site because UE4 C++ support is hot garbage. The best way I’ve found to play 2D and 3D sounds is as follows:
// In Constructor. This converts SoundCues in Unreal to something C++ can use
static ConstructorHelpers::FObjectFinder iTeleport(TEXT("/Game/Sound_Cues/Teleport"));
USoundCue* SoundCue = iTeleport.Object;
// When playing 2D sound
UAudioComponent* AudioComponent = UGameplayStatics::SpawnSound2D(this, SoundCue, volume_multiplier);
// When playing 3D sound
UAudioComponent* AudioComponent = UGameplayStatics::SpawnSoundAtLocation(this, SoundCue, location, FRotator::ZeroRotator, volume_multiplier, pitch_amount, 0.0f, nullptr, nullptr, true);
// Stopping a sound
AudioComponent->SetActive(false);