[UE5.1.1] Widget timer / animation supporting pause

In UE4 I implemented a c++ generated widget animation. It worked. This animation was used as a timer, since normal timers don’t execute in pause mode but widget animations do. In UE5 The animation only plays for a single tick before calling it’s “finished” delegate.
Did anyone else run into this? How to fix it?

The UE4 code:

// Create an animation, which will be used simply to loop a second.
const int32 FPS = 20;
const float Duration = 1.0f;
AnimAutoDecide = NewObject<UWidgetAnimation>(this, TEXT("AnimAutoDecide"));
if (IsValid(AnimAutoDecide)) {
	AnimAutoDecide->MovieScene = NewObject<UMovieScene>(this, FName("AnimAutoDecideScene"));
	AnimAutoDecide->MovieScene->SetDisplayRate(FFrameRate(FPS, 1));
	UMovieSceneEventTrack* NewMasterTrack = AnimAutoDecide->MovieScene->AddMasterTrack<UMovieSceneEventTrack>();
	UMovieSceneSection* NewSection = NewMasterTrack->CreateNewSection();
	NewSection->SetRange(TRange<FFrameNumber>(FMath::CeilToInt(FPS * Duration)));
	NewMasterTrack->AddSection(*NewSection);

	// Bind to the animation which will auto decide when it finishes.
	OnWidgetAnimAutoDecideFinished.BindDynamic(this, &UDecisionDialogWidget::ActOnWidgetAnimAutoDecideFinished);
	BindToAnimationFinished(AnimAutoDecide, OnWidgetAnimAutoDecideFinished);
}

What I attempted in UE5 to solve it…

// Create an animation, which will be used simply to loop a second.
const int32 Frames = 20;
AnimAutoDecide = NewObject<UWidgetAnimation>(this, TEXT("AnimAutoDecide"));
check(IsValid(AnimAutoDecide));
AnimAutoDecide->MovieScene = NewObject<UMovieScene>(this, FName("AnimAutoDecideScene"));
check(IsValid(AnimAutoDecide->MovieScene));
AnimAutoDecide->MovieScene->SetPlaybackRangeLocked(true);
AnimAutoDecide->MovieScene->SetPlaybackRange(0, Frames);
//AnimAutoDecide->MovieScene->SetDisplayRate(FFrameRate(Frames, 1));
UMovieSceneEventTrack* NewMasterTrack = AnimAutoDecide->MovieScene->AddMasterTrack<UMovieSceneEventTrack>();
UMovieSceneSection* NewSection = NewMasterTrack->CreateNewSection();
NewSection->SetRange(TRange<FFrameNumber>(Frames));
NewSection->SetStartFrame(TRangeBound<FFrameNumber>(0));
NewSection->SetEndFrame(TRangeBound<FFrameNumber>(Frames));
NewMasterTrack->AddSection(*NewSection);

// Bind to the animation which will auto decide when it finishes.
OnWidgetAnimAutoDecideFinished.BindDynamic(this, &UDecisionDialogWidget::ActOnWidgetAnimAutoDecideFinished);
BindToAnimationFinished(AnimAutoDecide, OnWidgetAnimAutoDecideFinished);

Sigh… Timer also not working.

UWorld* World = GetWorld();
	if (IsValid(World)) {
		World->GetTimerManager().ClearTimer(AutoDecideTimerHandle);
		FTimerDelegate TimerDelegate;
		TimerDelegate.BindUObject(this, &UDecisionDialogWidget::ActOnWidgetAnimAutoDecideFinished);
		GetWorld()->GetTimerManager().SetTimer(AutoDecideTimerHandle, 1.f, false);		
	}	
}

Anyone?

bump

AnimAutoDecide->MovieScene = NewObject<UMovieScene>(this, FName("AnimAutoDecideScene"));
// 10 seconds.
AnimAutoDecide->MovieScene->SetPlaybackRange(TRange<FFrameNumber>(0, 60000));
AnimAutoDecide->MovieScene->SetPlaybackRangeLocked(true);
}
1 Like