#[Tip] Auto-Propagate Widget Controller to Children Widgets

4 messages · Page 1 of 1 (latest)

elfin ginkgo
#

I updated my system to auto-propagate the controller to each UAuraUserWidget child. With this simple change, we can just set the controller on the top-most widget (such as the Attribute Menu or OverlayWidget ) and it propagates to all the children. You no longer need to manually set in the blueprint for each sub-widget. Saves time and eliminates errors. I'm lazy. 😉

void UAuraUserWidget::SetWidgetController(UObject* InWidgetController)
{
    WidgetController = InWidgetController;
    WidgetControllerSet();

    // Propagate the controller to each UAuraUserWidget child of this widget.
    // They in turn will propagate the controller down, so we only need to set
    // for the top-most widget.
    WidgetTree->ForEachWidget(
        [&](UWidget* Widget)
        {
            if (UAuraUserWidget* AuraWidget = Cast<UAuraUserWidget>(Widget))
            {
                AuraWidget->SetWidgetController(InWidgetController);
            }
        });
}
elfin ginkgo
#

As I've progressed through the course, these simple lines have allowed me to avoid all the busy work of calling SetWidgetController in the blueprints for child widgets. Worth doing!

#

[TIP] Auto-Propagate Widget Controller to Children Widgets

#

[Tip] Auto-Propagate Widget Controller to Children Widgets