Text Widgets - Preventing Overlapping

What would be the best way to prevent widget messages from overlapping one another? Like, I want one text widget to appear at a time; and, when certain trigger boxes are hit, one widget instantly disappears and the widget called by the trigger box takes its place. So, what would be the best way to make this happen?

I’m saving the reference to the text widget in GameInstance.
Make a variable called ActiveMessage, and whenever you show a message, save it to the variable. When a new message is about to be shown, check if the variable is valid, and if it is, destroy the previous message. And if a message disappears by itself after a delay or something, set the variable value to null as well.


Like a Boolean variable? And you mean adding the widget to GameInstance’s BP?

Not boolean, but a reference to the actual message widget. So that you know what widget to destroy.

Oh. So what kind of variable would I make, in association with a widget?

If there is a function in your message widget that needs to be called prior to destroying the widget, the variable type should be that of your widget class.
If you only call RemoveFromParent for the message widget, the variable type can simply be UserWidget.

1 Like

Hm. I think I might get an idea on what you mean. I did have a way to keep widgets from overlapping, but UE 4.27 griped at me after I play-tested in the editor. So hopefully, this will keep UE happy, if you know what I mean. Anyway, I’ll try that, in the morning.

Okay, I got it to work. Here’s what I did: I created two separate functions for each text widget. One creates and adds the widget to the viewport, while the other removes all widgets of a particular class with the Remove from Parent node.

Here is an example of a function that creates, declares and adds the widget to the screen.

Here is an example of a function that removes that same widget when called.

Anyway, thanks for your help! I hope this also helps anyone who runs into the same problem that I did.