When server travel (seamless travel) from the map to map - the player index of all connected players changes, and because of this the server (and only it) always goes wrong get player controller and get player Character. The server becomes a nonzero index. When clients are disconnected, the server again becomes a zero index. What is the problem?
I thought I was going crazy till I read your post.
For some reason the order is screwed up during the seamless travel. After all clients finish travel the order is restored (or at least, the local controller is #0 again).
To work around this, I wrote this small utility function to help me get the local playercontroller BEFORE all clients have finished travelling.
APlayerController * UUtilsLibrary::GetLocalPlayerController(UObject * WorldContextObject)
{
UWorld* world = WorldContextObject->GetWorld();
if (!world)
{
return nullptr;
}
for (FConstPlayerControllerIterator Iterator = world->GetPlayerControllerIterator(); Iterator; ++Iterator)
{
APlayerController* PC = Iterator->Get();
if (PC->IsLocalController())
{
return PC;
}
}
return nullptr;
}