Okay, I wrote my own function that recursively checks the activity of the current widget in the parent. It works perfectly.
Be careful, because it can affect performance if you have too many nested widgets. But I don’t think there will be any problems if there are about 100 iterations.
If you know another more correct way, please tell me. But I researched the source code of the engine and unfortunately did not see anything like that, so that widgets recursively inform child widgets that they are no longer active.
bool UWidgetFunctionLibrary::CheckWidgetIsActive(UWidget* widget)
{
if (!IsValid(widget))
{
return false;
}
while (IsValid(widget))
{
UWidget* parent = widget->GetParent();
if (!IsValid(parent) || !parent->GetCachedWidget().IsValid())
{
return widget->GetCachedWidget()->GetVisibility() == EVisibility::Visible
|| widget->GetCachedWidget()->GetVisibility() == EVisibility::HitTestInvisible
|| widget->GetCachedWidget()->GetVisibility() == EVisibility::SelfHitTestInvisible;
}
FArrangedChildren arrangedChildren(EVisibility::Visible);
parent->GetCachedWidget()->ArrangeChildren(parent->GetCachedWidget().Get()->GetPaintSpaceGeometry(), arrangedChildren);
bool wasFound = false;
for (int32 i = 0; i < arrangedChildren.Num(); i++)
{
if (arrangedChildren[i].GetWidgetPtr() == widget->GetCachedWidget().Get())
{
wasFound = true;
break;
}
}
if (!wasFound)
{
return false;
}
widget = parent;
}
return true;
}