How to use the OnAudioFinished Event in C++

Hello,

I am trying to use the OnAudioFinished Event in C++. I know how to use it in Blueprints but I do not know how to use it in code. I hope that someone could show me the right syntax and how to implement this event.

Thanks in advance

Hey -

The OnAudioFinsihed is a delegate in code. The best way to use it is to create your own function that binds to it. To do this you would need to create an audio component with UAudioComponent* CustomAudioComp as well as a function with the same parameter list as the FOnAudioFinished delegate. Since this delegate takes no arguments, your function would look something like void CustomAduioFuntion();. In the constructor of your class, you then do the actual binding. Since the class I was testing my setup was an actor class, the binding looks like this: CustomAudioComp->OnAudioFinished.AddDynamic(this, &AMyActor::CustomAudioFunction);. A more general form of the binding would look like [ComponentName]->OnAudioFinished.AddDynamic(this, &[Class]::[Function]); (without the square brackets). With this when OnAduioFinished is triggered for your actor’s audio component, your custom function triggers along with it.

Cheers

Works like a charm thank you.