Not Playing Animation (FadeOut) in UMG Widgets C++

Hi!!! I’m having a problem with a dialogue that I was trying to make a function in the Widget to set a text, prepare an animation and then add it to viewport and after the time has passed it removes it.

I have this .cpp of the DialogueWidget:

void UDialogueWidget::SetDialogueTextAndShow(FText text, float time)
{
	if (!IsInViewport()) {
		_dialogueText->SetText(text);
		PlayAnimation(_blend, 0.f, 1, EUMGSequencePlayMode::Forward, 1.f);
		PlayAnimation(_blend, time - 0.8f, 1, EUMGSequencePlayMode::Reverse, 1.f);
		
		AddToViewport();

		FTimerHandle dialogueTimerHandle;
		GetWorld()->GetTimerManager().SetTimer(dialogueTimerHandle, [this]() {
			RemoveFromParent();
		}, time, false);
	}
}

And this code in the .h:

UCLASS()
class SOPHIASFAULT_API UDialogueWidget : public UUserWidget
{
	GENERATED_BODY()
	
public:
	UPROPERTY(meta = (BindWidget), BlueprintReadWrite)
	class UTextBlock* _dialogueText;

	UPROPERTY(Transient, meta = (BindWidgetAnim), BlueprintReadWrite)
	class UWidgetAnimation* _blend;

	void SetDialogueTextAndShow(FText text, float time);
};

It doesn’t play any animation with this code.
I had another code that worked the FadeIn but not the FadeOut (it was the same code but instead of having just one _blend I had a _blendIn and _blendOut (I modified the Widget when I made the changes because it didn’t compile and because I didn’t need the _blendOut if it was the same that the _blendIn)).

If anyone can help me would be really apreciated :heart_hands:

Hi! I finally made a workaround.
I thought the parameter StartAtTime was something like, when the widget it’s in viewport for like 5s, if you pass 5s for the parameter, it will start. But no, the StartAtTime refers to the animation itself, if the animation last 1s and you PlayAnimation at 0.5s, it’ll start from 0.5 to 1s.

Here’s the final code that I did:

void UDialogueWidget::SetDialogueTextAndShow(FText text, float time)
{
	if (!IsInViewport()) {
		_dialogueText->SetText(text);
		AddToViewport();

		if (IsInViewport() && IsValid(_blendIn)) {
			PlayAnimation(_blendIn);
		}

		FTimerHandle animationTimerHandle;
		GetWorld()->GetTimerManager().SetTimer(animationTimerHandle, [this]() {
			if (IsValid(_blendOut)) {
				PlayAnimation(_blendOut);
			}
		}, time - 0.75f, false);

		FTimerHandle dialogueTimerHandle;
		GetWorld()->GetTimerManager().SetTimer(dialogueTimerHandle, [this]() {
			RemoveFromParent();
		}, time, false);
	}
}

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.