[UMG]Adding UButton to Horizontal Box

Hi Guys,

I want to create a horizontal box that will contain several buttons. I want the button added dynamically.
So in the Widget’s EventConstruct, I will call AddChildToHorizontalBox the pass a UButton as the argument. Until now, I create a custom User Widget that only contain a button. Then use CreateWidget and Add it to the HorizontalBox.
I think that it is overkill. It will be simpler if I can construct a UButton and add the constructed UButton to the HorizontalBox.
How can I construct a UButton?

Thanks

Solved!!

Using

  UButton* SampleButton = ConstructObject<UButton>(UButton::StaticClass(), this, FName("SampleButton"), GetMaskedFlags(RF_PropagateToSubObjects));

Same way we construct a UObject. :slight_smile: