Not sure if you still need help with this, but for anyone else that’s stuck, you can find an example of how to use this function in the GetAllWidgets function from the WidgetTree.cpp file:
void UWidgetTree::GetAllWidgets(TArray& Widgets) const
{
ForEachWidget([&] (UWidget* Widget) { Widgets.Add(Widget); });
}
A lambda function is required.