According to this post:
Something like this would work:
void USlateUtils::SetFocusOrDelayedFocus(APlayerController* InPlayerController, UWidget* InWidget) {
if (!IsValid(InPlayerController) || !IsValid(InWidget)) {
return;
}
InWidget->SetUserFocus(InPlayerController);
if (!InWidget->HasUserFocus(InPlayerController)) {
FLocalPlayerContext Context(InPlayerController);
if (ULocalPlayer* LocalPlayer = Context.GetLocalPlayer()) {
TOptional<int32> UserIndex = FSlateApplication::Get().GetUserIndexForController(LocalPlayer->GetControllerId());
if (UserIndex.IsSet()) {
LocalPlayer->GetSlateOperations().SetUserFocus(InWidget->GetCachedWidget().ToSharedRef());
}
}
}
}
That is bloody ugly and messes with the next frame. Something tells me we can’t we just enforce the “SafeWidget” creation at that point without messing up something else. Thoughts?