I am trying to Instantiate a UMG UButton inside a UVerticalBox from C++ and make it appear inside the canvas of the UMG Widget I created as BluePrint.
Then I want to manipulate its attributes from C++.
I have googled up and down and can’t find a single working example, neither for instantiating a UMG built-in type in C++ nor for displaying the created widget in the world.
Just to clarify, I am not looking to inherit a Blueprint Widget but instantiate UMG UI elements.
Here’s a snippet from a UMG base class where I construct a UImage and add it to a UHorizontalBox. The only prerequisite is that your C++ UMG base class provides a way for the blueprint to assign the UHorizontalBox (Panel), through a UHorizontalBox property or blueprint event that returns a UHorizontalBox.
UImage* IconWidget = WidgetTree->ConstructWidget<UImage>( UImage::StaticClass() );
IconWidget->SetBrushFromTexture( IconTexture );
UHorizontalBoxSlot* Slot = Panel->AddChildToHorizontalBox( IconWidget );
Slot->Padding.Right = 5.0f;
You should be able to replace the horizontal box with your vertical box, and the UImage with your UButton.