I am looking for a delegate to process when a UWidget “enters the view” and leaves it, example:
When it becomes visible.
When it enters visible screen space by widget position or by scrolling to it.
On Construct, when step 1. and 2. apply.
I have been scanning the widget code, slate and the viewport but I just can’t find it. I want this for a performance optimizer I am writing. Optimally the UWidget itself must bind to such delegate to process itself.
The challenge here is that:
Only the UUserWidget implements a delegate for change in visibility, but it isn’t executed when added / removed / or in / out of view by geometry.
Construct / WidgetRebuilt executes for the entire widget tree at once, not when the widgets actually become visible by some form of navigation.
This leaves me with hundreds of widgets I could technically optimize away at any given time.
Yes thanks for the suggestion. This event only executes on the UserWidget when you set its visibility variable. It does not reflect the actual visibility on the screen.
No idea if this gonna help, but I had similar issue (using pure C++) and my widget class inherited from UUserWidget. There is a method called NativeConstruct it you are navigating by CreateWidget<…> it can be overrided . Or use OnNativeVisibilityChanged event when you are dealing with visibility variable.
Construct runs when a widget is added or removed from a parent or viewport. OnVisibilityChanged does not reflect the actual state of the widget being visible. It might be visible but inside a list that is scrolled down to the bottom, making it invisible to the user. It might be translated off screen etc,.