How to use onaudiofinished to trigger event?

I have a method like this inside actor class:

for(int32 ni = 0; ni < Len;)
{ switch(nr){
case 0: play sound0;
propellerAudioComponent->OnAudioFinished.AddDynamic(this, &AMyclass::bools);

}
m_semaphore->Wait();
++ni;
}

void AMyclass::bools(){
m_semaphore->Trigger();
}

Problem is that the editor crashes when calling bools();
I want to wait until the first sound finishes then play the next sound.
Thankyou in advance.

Hey there, have you marked your bools function with UFUNCTION() ?

Thankyou for your quick reply and yes, its a ufunction it works very good. If I write something else in there it works. The problem is that I dont think I can use semaphore in an actor class, only in threads.

I haven’t used semaphores so i can’t really comment on that, but what exactly are you trying to do?

“I want to wait until the first sound finishes then play the next sound.”. Anyway I will try other way.

So you were trying to do an audio queue? you have a list of sounds and once one ends playing you want to play the next?

Yes, I think I found a way to do that.

You just need to have an array of sounds to play and an integer that controls the current sound you are playing, when you detect that the audio has finished you increment the integer and order the next sound to play so in pseudo code it would be something like this:

.h

TArray<USound *> SoundsToPlay;
int32 SoundIndex = 0;

.cpp

AMyClass::AMyClass

AudioComponent->OnAudioFinished.AddDynamic(this, &AMyClass::OnAudioFinished); 

AMyClass::PlaySound()
{
    if(SoundsToPlay.IsValidIndex(SoundIndex))
    AudioComponent->PlaySound(SoundsToPlay[SoundIndex]);
}

AMyClass::OnAudioFinished()
{
    SoundIndex++;

    PlaySound();
}

Yea, thats what I have thought of. Thankyou.