Runtime UI Animation

I hope this is the correct place where ask the question, otherwise I’m sorry.

I’ve a UMG Interface with a vertical box at center where to spawn alert messages (UTextBlock).


The alert messages must stay for 2 sec after this the message must fade out.

My idea is to do that with an animation, the problem is that the message (UTextBlock) is created using c++ and it’s added at runtime to the UVerticalBox.

I’ve tried to create animation using c++ for each message but I don’t know how it works and I’m stuck; here the code:

UWidgetAnimation* TestWidgetAnimation = NewObject<UWidgetAnimation>(this);
UMovieScene* TestMovieScene = NewObject<UMovieScene>(this);
FGuid AnimationTrackId;

UMovieSceneColorTrack* Track = TestMovieScene->AddTrack<UMovieSceneColorTrack>( AnimationTrackId );

If I create a “static” animation with editor is it possible to use as Template?

Hope you can help me thanks in advance.

Not really - building up the animation at runtime is possible, but not advisable (so expect dragons). The way you’d go about it to say, make a message that pops up - is just have a single widget be the message box container. You could keep that one widget around all the time (or create instances on an as needed basis - but making a single one would be more preformant), and whenever you need to issue a new message, have the message box update the text, and retrigger the animation to play - all housed inside this single widget asset. If you wanted you could have a message service or something in C++ with events for when messages appear. Then the widget could listen for those events via some exposed to blueprint interface. Alternatively, you could give the widget a native backend that knew how to update when messages arrived, bunch of other options if neither of those hit the mark.

Thanks for response this is a good approach. However you know where can I find an example or a doc on how can I create animation during runtime in c++? Or if you can give me a little hint on how to make. So I can compare the two approaches.
Thanks again for yours response that is very helpfull.