Default Widget Reference Value in Parent Widget Resets on Compile

Made a C++ class deriving from UUserWidget
Added an “EditAnywhere” variable, being a pointer to another widget.

I can set the default value of this through the Details panel to be one of the child elements, but as soon as I compile, this gets reset back to nullptr.
However, when I use this widget as an element in another widget, then I can set the reference and it will stay.

316399-widgetdefaultvalue.png

So it seems impossible to set the default value of a pointer inside a widget? It’s possible to set this up through the Preconstruct, but it is cleaner if I could just use the dropdown menu in the Details panel.

Any thoughts on this would be much appreciated!

Is M Sub Widget Test a UUserWidget*? I had the same issue with my class, just had to change it to be TSubclassOf and then construct it in the constructor like this:

if (WidgetClass)
{
		UUserWidget* Widget = CreateWidget<UUserWidget>(GetWorld(), WidgetClass);
		if (Widget)
		{	
            Widget->AddToViewport();
        }
}

Thanks for your reply :slight_smile:
Creating the widget like does change the hierarchy quite a bit, e.g. no longer hides/shows along with the parent, and cannot specify details like anchors in the details panel.
Want to actually assign the reference to a widget instance in the within the widget hierarchy. I assume it is because the parent widget gets constructed and intialised before the elements are valid. Makes sense, but not favorable. Could potentially change serialization based on name but would prefer not to :stuck_out_tongue:

I’m facing the same question, parent widget’s default value of User Widget reference will be reset after compilation. Now I set the default value by Event On Pre Construct in child widget, but it’s very very unmaintainable, now you have any solution to figure out this? Thank you.

I settled for setting the value on Preconstruct as well (on this very same widget itself though, not in child widgets).