Here’s my solution using coroutines. I needed a way to find out when a looping level sequence has reached the end of the timeline, and unfortunately the OnFinished and OnStop delegates don’t fire if the sequence is looping.
UE5Coro::TCoroutine<> USequencerTask::StartSequenceTimer()
{
// ensure the delegate never fires more than once per loop
bool bHasBroadcast = false;
while (IsValid(SequencePlayer) && SequencePlayer->IsPlaying())
{
const float CurrentTime = SequencePlayer->GetCurrentTime().AsSeconds();
const float EndTime = SequencePlayer->GetEndTime().AsSeconds();
if (bHasBroadcast && CurrentTime <= 0.1)
{
bHasBroadcast = false;
}
if (!bHasBroadcast && CurrentTime >= EndTime - 0.1f)
{
OnSequencePlayerLoop.Broadcast();
bHasBroadcast = true;
}
co_await UE5Coro::Latent::NextTick();
}
co_return;
}