I’m looking at the source from github, and I’m perplexed. The error seems to come from here:
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:
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.