You need to override SynchronizeProperties and call your SetStyle function before calling the parent function
void UUserWidgetTest::SynchronizeProperties()
{
SetStyle();
Super::SynchronizeProperties
}
Also, you need to manually call synchronize properties function for each umg widget type
void UYagMainWidget::SetStyle()
{
UE_LOG(LogTemp, Warning, TEXT("SetStyle"));
if (!WidgetTree) return;
UE_LOG(LogTemp, Warning, TEXT("SetStyle Widget OK"));
// get styles
YagGlobalStyle = FYagGlobalStyle::Get().GetWidgetStyle<FYagStyle>("YagGlobalStyle");
YagButtonStyle = YagGlobalStyle.YagButtonStyle;
YagTextStyle = YagGlobalStyle.YagTextStyle;
// set style on every child widget
WidgetTree->ForEachWidget(&](UWidget* Widget)
{
UButton* ThisButton = Cast<UButton>(Widget);
if (ThisButton)
{
ThisButton->SetStyle(YagButtonStyle);
**ThisButton->SynchronizeProperties();**
UE_LOG(LogTemp, Warning, TEXT("UButton style OK"));
}
UTextBlock* ThisTextBlock = Cast<UTextBlock>(Widget);
if (ThisTextBlock)
{
ThisTextBlock->SetColorAndOpacity(YagTextStyle.ColorAndOpacity);
ThisTextBlock->SetFont(YagTextStyle.Font);
**ThisTextBlock->SynchronizeProperties();**
UE_LOG(LogTemp, Warning, TEXT("UTextBlock style OK"));
}
UEditableTextBox* ThisEditableTextBox = Cast<UEditableTextBox>(Widget);
if (ThisEditableTextBox)
{
ThisEditableTextBox->WidgetStyle.SetForegroundColor(YagTextStyle.ColorAndOpacity);
ThisEditableTextBox->WidgetStyle.SetFont(YagTextStyle.Font);
**ThisEditableTextBox->SynchronizeProperties();**
UE_LOG(LogTemp, Warning, TEXT("UEditableTextBox style OK"));
}
});
}