Download

How does UAudioComponent::PlaybackCompleted work?

Hi all,

I have a simple OnOverlapBegin() that triggers an audio playing. When it’s finished I want to destroy the Actor it’s living on. PlaybackCompleted returns a void so i’m unsure just how to check it’s finished so that i can call my Destroy() function.

Something so simple, but causing me a brain melt lol Does anyone have any code snippets as i can’t find any online using PlaybackCompleted?

Best,
Matt.

Just set bAutoDestroy to true on the Audio Component and it’ll destroy its owner automatically once the playback is done.

Yeah i tried that. It does destroy the AudioComponent but not the Parent Actor it’s on. I want the entire thing to be destroyed.

You could just make a method on the Actor that plays the sound and subscribes to the OnPlaybackFinished, then just calls Destroy on itself once the callback happens. Tell the Actor to manage itself basically rather than you trying to figure out which Actor the playback finished on.

Or store a list of actors that you’ve called the Play on, when the callback happens, loop through and check “IsPlaying” and mark anything not playing as ready for clean up.

Does the owner tick? If so, you can always check AudioComponent::IsPlaying() or AudioComponent::GetPlayState() and destroy the owner accordingly.

If the owner doesn’t tick then you can subscribe to AudioComponent::OnAudioFinishedNative, like this:


AudioComponent->OnAudioFinishedNative.AddRaw(this, &MyObject::DestroyMeOnAudioFinished);