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

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.

u solved problem? i have this problem too

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

}