Hi! When creating a UHorizontalBox in c++ and adding another widget to it, e.g. UOverlay widget, then you CANNOT set the VerticalAlignment or HorizontalAlignment on the resulting UHorizontalBoxSlot object…
Below is a snippet of my code:
// Create HorizontalBox
WidgetTree->RootWidget = WidgetTree->ConstructWidget<UHorizontalBox>();
UHorizontalBox* HBox= (UHorizontalBox*)WidgetTree->RootWidget;
// Create Overlay
UOverlay* Overlay = WidgetTree->ConstructWidget<UOverlay>();
// Add Overlay to the HBox and set alignments
UHorizontalBoxSlot* HBoxSlot = HBox->AddChildToHorizontalBox(Overlay);
// These next two lines never work... There's a BUG in the implementation.
HBoxSlot->SetHorizontalAlignment(EHorizontalAlignment::HAlign_Fill);
HBoxSlot->SetVerticalAlignment(EVerticalAlignment::VAlign_Fill);
Here is source code from the Engine UMG module:
//Engine\Source\Runtime\UMG\Private\Components\HorizontalBoxSlot.cpp
void UHorizontalBoxSlot::SetHorizontalAlignment(EHorizontalAlignment InHorizontalAlignment)
{
HorizontalAlignment = InHorizontalAlignment;
if ( Slot ) // THIS CONDITION IS NEVER TRUE?
{
Slot->SetHorizontalAlignment(InHorizontalAlignment);
}
}
Slot is never true in this case. It is always a Nullptr, and therefore calling SetHorizontalAlignment() or SetVerticalAlignment() doesn’t work in c++.
Is it a bug or am I simply misusing these functions?