# how can i expose variable to create widget

**URL:** <https://forums.unrealengine.com/t/how-can-i-expose-variable-to-create-widget/883039>\
**Category:** C++\
**Tags:** unreal-engine, CPP, question, Blueprint\
**Created:** [April 10, 2023, 10:32am UTC](https://forums.unrealengine.com/t/how-can-i-expose-variable-to-create-widget/883039 "2023-04-10T10:32:58Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![emir143](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@emir143](https://forums.unrealengine.com/u/emir143)\
**Post date:** [April 10, 2023, 10:32am UTC](https://forums.unrealengine.com/t/how-can-i-expose-variable-to-create-widget/883039/1 "2023-04-10T10:32:58Z")

</div>

hi  
so i have made a inventory in blueprint as an assignment, and im trying to move it to c++, but the problem i have is that in one of the UI’s blueprint code, im using a create widget and i have referenced another UI widget class, so when i have done that, it exposes one of the variables that i have in that UI blueprint class

my question is, how can i expose one of the variable in create widget()?

for better understanding: i want to recreate this  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/d/b/5db3e5853db0caf433efb65322d8def14e87c18a.png)  
the create widget under, is an example to see the difference.  
how can i add the parent variable to Create widget() in c++?

---

<div class="post-metadata">

**Author:** ![High500](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/high500/32/906557_2.png) [@High500](https://forums.unrealengine.com/u/High500)\
**Post date:** [April 10, 2023, 11:55am UTC](https://forums.unrealengine.com/t/how-can-i-expose-variable-to-create-widget/883039/2 "2023-04-10T11:55:43Z")

</div>

hi @emir143

in the details panel of the variable tick expose on spawn

---

<div class="post-metadata">

**Author:** ![emir143](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@emir143](https://forums.unrealengine.com/u/emir143)\
**Post date:** [April 10, 2023, 12:53pm UTC](https://forums.unrealengine.com/t/how-can-i-expose-variable-to-create-widget/883039/3 "2023-04-10T12:53:22Z")

</div>

i have already done that but how can i implement it on c++ CreateWidget() like in blueprint?

---

<div class="post-metadata">

**Author:** ![High500](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/high500/32/906557_2.png) [@High500](https://forums.unrealengine.com/u/High500)\
**Post date:** [April 10, 2023, 1:10pm UTC](https://forums.unrealengine.com/t/how-can-i-expose-variable-to-create-widget/883039/4 "2023-04-10T13:10:57Z")

</div>

hmm have a look at what this guy says

> [@How do i set values to exposed variables using CreateWidget in c++?](https://forums.unrealengine.com/t/how-do-i-set-values-to-exposed-variables-using-createwidget-in-c/340706/3):
>
> “Exposed on Spawn” is only relevant in BP. In C you would set the values as you would any other property. If they’re public, you can just set them. If they’re private you can use a Setter method. UMyWidgetClass\* MyNewWidget = T\<UMyWidgetClass\>CreateWidget(Owner, MyWidgetClassPtr); if (MyNewWidget) { //set public variable MyNewWidget-\>MyPublicFloat = 1.0f; //set private variable using setter method defined in your widget class MyNewWidget-\>SetMyPrivateFloat(5.0f); }

im guessing as soon as you create the widget you set its variables from that object

---

<div class="post-metadata">

**Author:** ![emir143](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@emir143](https://forums.unrealengine.com/u/emir143)\
**Post date:** [April 10, 2023, 1:18pm UTC](https://forums.unrealengine.com/t/how-can-i-expose-variable-to-create-widget/883039/5 "2023-04-10T13:18:30Z")

</div>

so if i understand correctly, i shouldnt write it inside of the CreateWidget() but instead under/after it. so it do be like as if im reassigning the variable?

---

<div class="post-metadata">

**Author:** ![High500](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/high500/32/906557_2.png) [@High500](https://forums.unrealengine.com/u/High500)\
**Post date:** [April 10, 2023, 1:32pm UTC](https://forums.unrealengine.com/t/how-can-i-expose-variable-to-create-widget/883039/6 "2023-04-10T13:32:08Z")

</div>

yeah judging by that im guessing so which would make sense in usual c++, guessing the blueprint expose is to optimise the amount of nodes in BP only so dont have to do another call to the BP

---

<div class="post-metadata">

**Author:** ![emir143](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@emir143](https://forums.unrealengine.com/u/emir143)\
**Post date:** [April 10, 2023, 2:21pm UTC](https://forums.unrealengine.com/t/how-can-i-expose-variable-to-create-widget/883039/7 "2023-04-10T14:21:17Z")

</div>

i see now, thank you for your answering and time 🙂

---

<div class="post-metadata">

**Author:** ![High500](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/high500/32/906557_2.png) [@High500](https://forums.unrealengine.com/u/High500)\
**Post date:** [April 10, 2023, 4:25pm UTC](https://forums.unrealengine.com/t/how-can-i-expose-variable-to-create-widget/883039/8 "2023-04-10T16:25:15Z")

</div>

no problemo, please mark the as resolved so that others can benefit if they find this 🙂
