CreateWidget cannot be used on Player Controller with no attached player

I’m looking at the source from github, and I’m perplexed. The error seems to come from here:

https://github.com/EpicGames/UnrealEngine/blob/2bf1a5b83a7076a0fd275887b373f8ec9e99d431/Engine/Source/Runtime/UMG/Private/UserWidget.cpp#L1902



else if (!OwnerPC.Player)
{
     const FText FormatPattern = LOCTEXT("NoPlayer", "CreateWidget cannot be used on Player Controller with no attached player. {PlayerController} has no Player attached.");
     FFormatNamedArguments FormatPatternArgs;
     FormatPatternArgs.Add(TEXT("PlayerController"), FText::FromName(OwnerPC.GetFName()));
     FMessageLog("PIE").Error(FText::Format(FormatPattern, FormatPatternArgs));
}


Now, this means that the PlayerController doesn’t have a Player. But, I’m creating a PC through GameStatics:

https://github.com/EpicGames/UnrealEngine/blob/2bf1a5b83a7076a0fd275887b373f8ec9e99d431/Engine/Source/Runtime/Engine/Private/GameplayStatics.cpp#L264


APlayerController* UGameplayStatics::CreatePlayer(const UObject* WorldContextObject, int32 ControllerId, bool bSpawnPlayerController)
{
UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::LogAndReturnNull);
FString Error;

ULocalPlayer* LocalPlayer = World ? World->GetGameInstance()->CreateLocalPlayer(ControllerId, Error, bSpawnPlayerController) : nullptr;

if (Error.Len() > 0)
{
UE_LOG(LogPlayerManagement, Error, TEXT("Failed to Create Player: %s"), *Error);
}

return (LocalPlayer ? LocalPlayer->PlayerController : nullptr);
}

Which should have a player attached.