# Default Widget Reference Value in Parent Widget Resets on Compile

**URL:** <https://forums.unrealengine.com/t/default-widget-reference-value-in-parent-widget-resets-on-compile/472113>\
**Category:** UI\
**Tags:** reference, object, unreal-engine, pointer, Widget, question, UMG\
**Created:** [September 29, 2020, 9:30am UTC](https://forums.unrealengine.com/t/default-widget-reference-value-in-parent-widget-resets-on-compile/472113 "2020-09-29T09:30:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Josterd](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Josterd](https://forums.unrealengine.com/u/Josterd)\
**Post date:** [September 29, 2020, 9:30am UTC](https://forums.unrealengine.com/t/default-widget-reference-value-in-parent-widget-resets-on-compile/472113/1 "2020-09-29T09:30:01Z")

</div>

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](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/1/e/91e239fe715c842e109397dfed4d8208ae0be4ce.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!

---

<div class="post-metadata">

**Author:** ![MagicznaFlet6](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MagicznaFlet6](https://forums.unrealengine.com/u/MagicznaFlet6)\
**Post date:** [September 29, 2020, 10:44am UTC](https://forums.unrealengine.com/t/default-widget-reference-value-in-parent-widget-resets-on-compile/472113/2 "2020-09-29T10:44:40Z")

</div>

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();
        }
}
```

---

<div class="post-metadata">

**Author:** ![Josterd](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Josterd](https://forums.unrealengine.com/u/Josterd)\
**Post date:** [September 29, 2020, 11:16am UTC](https://forums.unrealengine.com/t/default-widget-reference-value-in-parent-widget-resets-on-compile/472113/3 "2020-09-29T11:16:33Z")

</div>

Thanks for your reply 🙂  
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 😛

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_e46a9c97](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_e46a9c97](https://forums.unrealengine.com/u/anonymous_user_e46a9c97)\
**Post date:** [November 11, 2020, 7:38am UTC](https://forums.unrealengine.com/t/default-widget-reference-value-in-parent-widget-resets-on-compile/472113/4 "2020-11-11T07:38:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Josterd](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Josterd](https://forums.unrealengine.com/u/Josterd)\
**Post date:** [November 11, 2020, 9:32am UTC](https://forums.unrealengine.com/t/default-widget-reference-value-in-parent-widget-resets-on-compile/472113/5 "2020-11-11T09:32:13Z")

</div>

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