Event when a widget is "in view"?

I am looking for a delegate to process when a UWidget “enters the view” and leaves it, example:

  1. When it becomes visible.
  2. When it enters visible screen space by widget position or by scrolling to it.
  3. 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:

  1. 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.
  2. 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.

Bump

do you trying OnVisibilityChanged

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.

There is no such event for this, widgets will not tick unless painted, but that’s up to the parent to decide whether to paint or not.

1 Like

This sounds right, I’ll have to research if I can use the Paint method on the UWidget or a parent to implement something similar then

Yikes, OnPaint runs like tick even when a widget has been added but not rendered yet.

Since this “tick” is running anyhow, it seems I can write a custom implementation on OnPaint.

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,.