# Pass exposed-on-spawn parameter to child Widget

**URL:** <https://forums.unrealengine.com/t/pass-exposed-on-spawn-parameter-to-child-widget/477595>\
**Category:** UI\
**Tags:** Variable, expose-on-spawn, unreal-engine, Widget, question\
**Created:** [January 21, 2021, 4:53pm UTC](https://forums.unrealengine.com/t/pass-exposed-on-spawn-parameter-to-child-widget/477595 "2021-01-21T16:53:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_c66565b6](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_c66565b6](https://forums.unrealengine.com/u/anonymous_user_c66565b6)\
**Post date:** [January 21, 2021, 4:53pm UTC](https://forums.unrealengine.com/t/pass-exposed-on-spawn-parameter-to-child-widget/477595/1 "2021-01-21T16:53:58Z")

</div>

I have a widget `ChildWidget` that is used in another widget `ParentWidget`

In `ChildWidget`, I have exposed on spawn a variable `Text` of type Text, that I am using in the Pre Construct with a Text widget.

 ![327778-childwidget-bp.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/a/4/6a4884fac618f6d03447532254081043fb66de42.png)

 ![327779-childwidget-designer.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/a/0/0a0d46cc50d23e8c522c3bf8762cc744e9ce852c.png)

In `ParentWidget`, I have added `ChildWidget` to the hierarchy. I set its `Text` parameter value to “(parent default)”. I also exposed on spawn another variable `Text` of type Text. In the Pre Construct event, I assign `ChildWidget`’s `Text` variable with the value from `ParentWidget`’s `Text`.

 ![327780-parentwidget-bp.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/d/c/ddc58d6f56b1c61ec8cf653b1b50d478abda851d.png)

 ![327781-parentwidget-designer.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/c/7/ec72df17c120fd27a8fabf971916325e6ea22f37.png)

In the level blueprint, I create a `ParentWidget` with “Level value” as `Text_parent`’s value.

 ![327782-level-bp.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/8/2/b82f361be7705a7e5d7e7286bd5b6bd4df735769.png)

However when I hit play, the value used in `ChildWidget` is not the value passed from the level blueprint (“Level value”), but the value set in `ParentWidget` (“Parent default”), because `ChildWidget`’s Pre Construct is executed before `ParentWidget`’s

How can I achieve that ? The idea is to have a ChildWidget with some configurable content, thanks to an public variable, and initalized in Pre Construct or Contruct. Here I used a simple text here, but it could be anything more complex. And use it in a parent widget also in a configurable manner when I create the widget.

Like in pseudo-c++ code, if I called `ChildWidget`’s “constructor” from `ParentWidget`’s "constructor, while forwarding the parameters

```
class ChildWidget : Widget
{
public:
    ChildWidget(Text text);
}

class ParentWidget : Widget
{
public:
    ParentWidget(Text text):
private:
    ChildWidget m_childWidget;
}

ParentWidget::ParentWidget(Text text) : m_childWidget(text)
{
}

void LevelBlueprint()
{
    auto widget = ParentWidget("Level value");
}

```

---

<div class="post-metadata">

**Author:** ![Alekann01](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Alekann01](https://forums.unrealengine.com/u/Alekann01)\
**Post date:** [January 21, 2021, 6:04pm UTC](https://forums.unrealengine.com/t/pass-exposed-on-spawn-parameter-to-child-widget/477595/2 "2021-01-21T18:04:07Z")

</div>

Hi m.leber

The easiest way would be to pass a reference from the parent widget to the child widget. This way in the child can access all the properties from the parent directly from the binding tab.

This is a screenshot from another answer where I showed how to bind an output to a variable in the player state. However it works the same.

 ![321915-hud-2.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/1/8/a181d859f9eff913ddfc32e0e87e289e157e6560.png)

Hope this helps.

Alex

---

<div class="post-metadata">

**Author:** ![Alekann01](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Alekann01](https://forums.unrealengine.com/u/Alekann01)\
**Post date:** [January 21, 2021, 6:06pm UTC](https://forums.unrealengine.com/t/pass-exposed-on-spawn-parameter-to-child-widget/477595/3 "2021-01-21T18:06:16Z")

</div>

To your screenshot regarding the Pre Construct. If you change a variable in the parent widget on pre construct / construct. You will need to call some kind to function to refresh the child widget (if the data is not directly bound).

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_c66565b6](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_c66565b6](https://forums.unrealengine.com/u/anonymous_user_c66565b6)\
**Post date:** [January 22, 2021, 9:09am UTC](https://forums.unrealengine.com/t/pass-exposed-on-spawn-parameter-to-child-widget/477595/4 "2021-01-22T09:09:54Z")

</div>

Hi, thank you for your answer.  
Regarding the reference to the parent into the child, I would like to design the child to be generic, composable and agnostic of its use, ie to be able to be used inside any widget or even without a parent widget (created and added to the viewport directly), like any other widget

And regarding the binding, the text was just and example, I would just like to be able to use a param in the construct script

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_c66565b6](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_c66565b6](https://forums.unrealengine.com/u/anonymous_user_c66565b6)\
**Post date:** [January 22, 2021, 9:11am UTC](https://forums.unrealengine.com/t/pass-exposed-on-spawn-parameter-to-child-widget/477595/5 "2021-01-22T09:11:37Z")

</div>

In this case, the child widget has to be constructed first with some arbitrary parameter (the unused value set in the parent), and the, changed with an updated value when the parent is constructed ?

---

<div class="post-metadata">

**Author:** ![Alekann01](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Alekann01](https://forums.unrealengine.com/u/Alekann01)\
**Post date:** [January 22, 2021, 11:05am UTC](https://forums.unrealengine.com/t/pass-exposed-on-spawn-parameter-to-child-widget/477595/6 "2021-01-22T11:05:56Z")

</div>

You have a couple of options.

1. Store a reference to the child in the parent. When the parent updates, add logic to manually push that data to the child widget. Event Dispatchers could be extremely useful here depending on the complexity and frequency of the data updating.

2. Use a base class.  
Create a base class called “WBP\_Master” or something similar and add a variable “Parent” of the same type with expose on spawn checked. Make sure you remove all child widgets from the Master’s designer view. Reparent your other widgets to this class.

Now your widgets will have the option to set a parent if required and then you just add the logic if that parent is valid (obviously the variable will need to be set when it’s spawned). From there, you can cast to the type of the parent widget and access its data. However, if you want it to remain completely universal, you can add further variables in the WBP\_Master so there is no need for any further casting.

1. You could also push the data to some universal space when it’s updated on the parent and then access it from the child without any relationship with the parent required.

Hope these options help.

Regarding your comment:

> In this case, the child widget has to  
> be constructed first with some  
> arbitrary parameter (the unused value  
> set in the parent), and the, changed  
> with an updated value when the parent  
> is constructed ?

The child wouldn’t need to be constructed first, just the reference needs to be set at some point before the binding will update.

Good luck

Alex
