UMG and C++ variables

So, I’ve created a c++ class derived from uuserwidget. I then parent a blueprint created widget to this code widget. In the code widget, I’m able to create a UButton variable. However, I’m unable to add this variable to my blueprint widget’s canvas in Desgner mode.

I want to be able to modify this button in code. As it stands, I have to add the button as a variable on the blueprint widget’s designer tab. Then at construction, I set my code UButton equal to the Blueprint Designer button. I’m then able to manipulate the button in code.

That’s a bit clunky and requires that I remember to set that relationship up in blueprint.

Any thoughts on just making the UMG designer see the code button?

Just making varable is not enouth, you need to construct the widget (i think same as you do with components in actor with subobject in constructor, i’m 100% not sure with this, you could try use NewObject in OnConstrct) and add to container, either UUserWidget you use or other panel widget you use some panel widget which also will need to construct in C++ and then you set widget varable. To attach widget to parent widget you use slot varable:

And on panel widget that can hold more then one widget you AddChild function:

I’m not quite sure I follow you. I’m trying to add a UButton to a widget, not another widget to an existing widget. Do I still need to make a slot to add the UButton to the designer? I’m sorry, I’m just a little confused.

I basically want the button in this image from the Designer tab:

90413-capture.png

to be the variable I create in C++.

Is that even possible?

Then there no way to do that in blueprint… but you can get that button in C++ :slight_smile: USe that Slot varable i showed you, the button is a root it should bei n slot of you UUserWidget.