# How do i set values to exposed variables using CreateWidget in c++?

**URL:** <https://forums.unrealengine.com/t/how-do-i-set-values-to-exposed-variables-using-createwidget-in-c/340706>\
**Category:** UI\
**Tags:** variables, spawn, create, unreal-engine, Widget, CPP, question\
**Created:** [December 6, 2015, 10:48pm UTC](https://forums.unrealengine.com/t/how-do-i-set-values-to-exposed-variables-using-createwidget-in-c/340706 "2015-12-06T22:48:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![xlar8or](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/xlar8or/32/710746_2.png) [@xlar8or](https://forums.unrealengine.com/u/xlar8or)\
**Post date:** [December 6, 2015, 10:48pm UTC](https://forums.unrealengine.com/t/how-do-i-set-values-to-exposed-variables-using-createwidget-in-c/340706/1 "2015-12-06T22:48:03Z")

</div>

I’m using CreateWidget function to create a new widget and it’s working fine. The problem is when i try to create widgets that have variables exposed on spawn, how do i set the values for that in c++? Thank you.

---

<div class="post-metadata">

**Author:** ![jetset\_3566](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jetset_3566/32/466471_2.png) [@jetset\_3566](https://forums.unrealengine.com/u/jetset_3566)\
**Post date:** [April 18, 2018, 10:56am UTC](https://forums.unrealengine.com/t/how-do-i-set-values-to-exposed-variables-using-createwidget-in-c/340706/2 "2018-04-18T10:56:10Z")

</div>

u solved problem? i have this problem too

---

<div class="post-metadata">

**Author:** ![GigasightMedia](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@GigasightMedia](https://forums.unrealengine.com/u/GigasightMedia)\
**Post date:** [April 19, 2018, 7:25am UTC](https://forums.unrealengine.com/t/how-do-i-set-values-to-exposed-variables-using-createwidget-in-c/340706/3 "2018-04-19T07:25:13Z")

</div>

“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);

}
```
