# 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:** 1\
**Showing post:** 3

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

}
```

---

_[View the full topic](https://forums.unrealengine.com/t/how-do-i-set-values-to-exposed-variables-using-createwidget-in-c/340706)._
