**UMG, Get Widgets Of Class
Updated!**
** node will be in a near future engine release! Epic accepted my github pull request!**
You can start playing with it now though, as part of my plugin!
Now you have an optional bool filter to only return widgets that are at the top level, see Darnell’s comment for more information
**My C++ Code For Node**
```
void UVictoryBPFunctionLibrary::GetAllWidgetsOfClass(UObject* WorldContextObject, TSubclassOf<UUserWidget> WidgetClass, TArray<UUserWidget*>& FoundWidgets,bool TopLevelOnly)
{
//Prevent possibility of an ever-growing array if user uses in a loop
FoundWidgets.Empty();
//~~~~~~~~~~~~
if(!WidgetClass) return;
if(!WorldContextObject) return;
UWorld* const World = GEngine->GetWorldFromContextObject(WorldContextObject);
if(!World) return;
//~~~~~~~~~~~
for(TObjectIterator<UUserWidget> Itr; Itr; ++Itr)
{
if(Itr->() != World) continue;
//~~~~~~~~~~~~~~~~~~~~~
if( ! Itr->IsA(WidgetClass)) continue;
//~~~~~~~~~~~~~~~~~~~
//Top Level?
if(TopLevelOnly)
{
//only add top level widgets
if(Itr->GetIsVisible()) //IsInViewport in 4.6
{
FoundWidgets.Add(*Itr);
}
}
else
{
//add internal widgets
FoundWidgets.Add(*Itr);
}
}
}
```
Pic