All UserWidgets In Viewport

i know there is IsInViewport to check if a userwidget is currently in the viewport. but is there a way to list all userwidgets that are currently in the viewport? or do i have to create a list on my own?

Hello!

Just save references in a TArray ( if they are instances of the same userWidget )

TArray is the Ue4 array and it is similar to a STL std::array, it has many functionalities like addunique,sort…

Or you can use a map made of a bool(isInViewport)and the reference to your widget

This way you can add ,remove and add again a widget without have to create it again, because it is still referenced and thus not garbage collected.
And easily check to see if it is in viewport.

Hope it helps!

hi, if i have to manage it on my own, i guess i will simply use a set. but i was hoping to avoid the extra work. :smiley:

Ok then use getAllWidgetsOfAClass and filter with isInViewport…

Hey,

One method you can use (that will be costly) is (this is done from the perspective of a UUserWidget in my example):

TArray<UWidget*> AllWidgets;
WidgetTree->GetAllWidgets(AllWidgets);

You’ll need to #include “WidgetTree.h”, but this will give you an array of all top level widgets. It will not penetrate other UUserWidgets, though. Luckily, WidgetTree is a public member of UUserWidget, so you can recursively iterate through all UUserWidget.

If this doesn’t work for you, let me know.

Glad to hear that! :slight_smile:

hi again, i dont need to know the widgets of a class. i need to know the userwidgets that have been added to the viewport (CreateWidget → AddToViewport). but your answer lead me to GetAllWidgetsWithInterface, which i could use for exactly that. thanks!

hi and thank you for your reply. im looking for a blueprint solution though. :smiley: for now, im using GetAllWidgetsWithInterface which does exactly what i want.

This is the first result on Google so I’ll give it a solution:

353123-getalluserwidget.png

This should get all user widgets in viewport.

1 Like