Where are you trying to clear it?
- Inside of a widget
- Inside of a widgetComponent
You could try checking the RemoveWidgetFromScreen() function
if you want to remove a widget then you can call RemoveFromParent(); directly on it.
it all depends on the expanded use case that you need.
This is from the widgetComponent
void UWidgetComponent::SetWidgetClass(TSubclassOf<UUserWidget> InWidgetClass)
{
if (WidgetClass != InWidgetClass)
{
WidgetClass = InWidgetClass;
if (FSlateApplication::IsInitialized())
{
if (HasBegunPlay() && !GetWorld()->bIsTearingDown)
{
if (WidgetClass)
{
UUserWidget* NewWidget = CreateWidget(GetWorld(), WidgetClass);
SetWidget(NewWidget);
}
else
{
SetWidget(nullptr);
}
}
}
}
}
And in SetWidget
void UWidgetComponent::SetWidget(UUserWidget* InWidget)
{
if (InWidget != nullptr)
{
SetSlateWidget(nullptr);
}
if (Widget)
{
RemoveWidgetFromScreen();
}
Widget = InWidget;
UpdateWidget();
}