I am a bit late to the party, but a possible solution without losing the advantages of the menu stack is to walk up in the slate widget hierarchy and hide the images. Example code:
void UMyEpicFunctionLibrary::RemoveMenuStackBackground(UWidget* Widget)
{
if (Widget == nullptr)
{
return;
}
SOverlay* FirstOverlay = nullptr;
for (TSharedPtr<SWidget> SlateWidget = Widget->GetCachedWidget(); SlateWidget.IsValid(); SlateWidget = SlateWidget->GetParentWidget())
{
if (SlateWidget->GetType() == "SOverlay")
{
FirstOverlay = static_cast<SOverlay*>(SlateWidget.Get());
break;
}
}
if (FirstOverlay == nullptr)
{
return;
}
FChildren* ChildrenPtr = FirstOverlay->GetChildren();
if (ChildrenPtr == nullptr)
{
return;
}
for (int32 i = 0; i < ChildrenPtr->Num(); ++i)
{
TSharedRef<SWidget> OverlayChild = ChildrenPtr->GetChildAt(i);
if (OverlayChild->GetType() == FName("SImage"))
{
SImage* Image = static_cast<SImage*>(OverlayChild.ToSharedPtr().Get());
Image->SetVisibility(EVisibility::Hidden);
}
}
}
Unfortunately it does not work in OnConstruct yet, because the slate widget does not have its parent set. One frame delay would lead to a visual glitch. After some debugging I found a glitch free solution:
- Set the widget to Focusable
- Call the function from
NativeOnFocusReceived
(C++) or fromOnFocusReceived
(BP).