BindUObject for OnAudioFinished errors

https://answers.unrealengine.com/questions/165669/override-audiocomponent-onaudiofinished-func.html

I tried binding the OnAudioFinished delegate as I was instructed above but I get many errors depending on what I do.

I’ve followed a few tutorials and to no avail.

//Inside .cpp constructor of class of which the .h file imports AudioComponent.h
OnAudioFinished.BindUObject(this, &AAudioPlayer::AudioFinished);

//Just an empty function to be called
void AAudioPlayer::AudioFinished()
{

}


//inside .h file
DECLARE_DELEGATE_TwoParams(OnAudioFinished, FString, FString);

void AudioFinished();

The BindUObject has a few errors.

Under the ‘.’ I get a “expected an identifier” error, under ‘this’ I get “expected a type identifier” error, under the ‘&’ address character I get “expected a type specifier” error. It’s almost as if It’s giving me errors like the bind function is trying to be a function declaration which is very odd.

I have no syntax errors in the file and if I take the line out everything else works fine.

Thanks.

Your actor needs an AudioComponent on it.

Once you have that instead of declaring a new delegate you’d simply do this.

MyAudioComponent->OnAudioFinished.BindUObject(this, &AAudioPlayer::AudioFinished);

Now when I use .BindUObject on my audiocomponent’s OnAudioFinished, it gives me an error on the BindUObject telling me that “class FOnAudioFinished has no member BindUObject”

I also tried using
AudioComp->OnAudioFinishedNative.AddUObject(this, &AAudioPlayer::AudioFinished);
But I get an error under the ‘.’ saying “no instance of overloaded function …::AddUObject… matches the argument list”

And get a similar error on AudioComp->OnAudioFinishedNative.AddUFunction(this, AAudioPlayer::AudioFinished);

And AudioComp->OnAudioFinishedNative.AddUFunction(this, &AAudioPlayer::AudioFinished);

Any update on this? I’m hitting this issue with 4.12.5

I can bind to OnSubtitlesQueued with no problem though…

Got it!

AudioComponent->OnAudioFinished.AddDynamic(this, ADialogManager::AudioClipFinished)

Nice. Now whoever searches this will find their answer hopefully.

I ended up writing a multithreaded process that checked the current play location of each track against the track length to determine if it had ended or not. This ended up giving me much more control as I could transition to similar tracks in the song at the exact same point in a measure, instead of just at the end. I called this hot-swapping, which sounded really cool.