Check if widget is visible / on screen

How do we check if a Widget is currently on the screen before we “Remove from Parent?”

If true, remove.
If false, do nothing.

Thanks!

3 Likes

Use the IsVisible node from the Widget blueprint.

68962-ue4_widget_visible.png

1 Like

In 4.11 version of the engine I use IsInViewport function. I’m not sure if it’s new or already was present in previous versions.

4 Likes

Hello.
What about 4.21.1? Cant find any of those :frowning:

I guarantee that both of those functions exist in 4.22 & 4.23
To verify this for yourself you can right click in any empty section of event graph, uncheck “context sensitive” and type in “is visible” and “is in viewport”.
If you are dragging off a node, right clicking, and typing in “is visible” or “is in viewport” then you are not dragging off a valid target, make sure you are targeting a widget.

1 Like

Currently using UE 5.3 and I would like to know if there is any concenseous on which to use?
(is visible VS is in viewport)

2 Likes

How to do this “Tutorial Screen Widget” Reference node ???

That is a variable. Once you have a variable of type {Your Widget} in the blueprint you can just drag it into the scene or right click and select “Get {Your Widget’s variable name}”. In this instance his variable is called “Tutorial Screen Widget”

Is Visible

IsVisible is a very fast check, as it simply checks if the Visibility property of the widget is any of:

  • Visible
  • Hit-test invisible
  • Self hit-test invisible

However, its weakness is that if you call it on the very first frame of a widget’s existence, it may return false because the underlying Slate widget may not be valid yet, regardless of its initial Visibility state.

To overcome this problem, use GetVisibility and check the current state yourself. The internal Visibility property is valid even before the underlying Slate widget is created, so it’s reliable even on the first frame. A way to “nicely” convert it to bool is to drag a line from its result and create a Select node from it. Then connect its result to any bool input and that sets its type to bool. All that’s left is to check the right boxes.


Is In Viewport

I haven’t used it, but from the source code it seems it’s only true for root widgets: those you add directly to the viewport. I expect it to not work as the name implies for sub-widgets. It’s also a slower function, as it checks the Game Viewport Subsystem to ask if the widget is part of its list of widgets. I wouldn’t call it in a loop or other hot path if could avoid it.

Might I ask for some assistance in the opposite direction, please?

When I am done with a widget I call “Remove from parent” but the promoted variable still seems to hold a reference to it since “Is valid” returns true. So if I want to show the widget again, what do I do?

Add to viewport ? Change visibility ? Something else?

At the moment I respawn the widget but it seems my events then fire off twice or more times (on screen logs confirm)

So what is the right way to make a widget that IS spawned but NOT visible, visible after having called Remove From Parent?

Alternatively, what is the right way to completely destroy a widget after it’s use? So far I have only ever seen mention of removing it from it’s parent

EDIT: I found the answer here

Just set the promoted variable to null after removing the widget from parent