One feature that I’ve wanted for a while is UMG widget events that fire when the widget is added to or removed from the viewport or another widget. You could compare this to the actor’s BeginPlay/EndPlay events: I use EndPlay often to cleanup objects that I created or events I bound at BeginPlay. Something similar for widgets would be really useful in my opinion. I’m curious if others out there are interested in such a feature. If you are, good news: I’ve got this working and have created a pull request on Github. Please leave a comment there to indicate general interest in this feature.
The idea is not only to allow widgets to respond to them being added/removed via Event Added/Removed, but also to let actors respond to a specific widget being added or removed by binding events to OnAdd/OnRemove delegates on the widget. Take this situation: an actor creates a widget and updates the information displayed on it every Tick. If the widget has a way to be removed outside of the actor’s influence (for example it can be closed by clicking a close button), it would be useful if the actor has a way to be notified of this so he can stop updating the widget.
Here is how using the events and delegates looks in blueprint.
This PlayerController reacts to the ParentWidget being shown and hidden.
This ParentWidget reacts to itself being shown and hidden, and to its own created children being shown and hidden.
This ChildWidget reacts to itself being shown and hidden.
And here it is in action:
So what do you guys think? Would this be a useful to you?