Hi!
Having some issues with networking and changing levels.
We have a lobby and a game world. All players connect to a lobby, and when they have prompted to the server that they are “ready” I then call GetWorld()->ServerTravel("Game/Maps/MyMap")
on the server, and it starts transitioning to MyMap. It does not, however, transition the clients correctly. No new PlayerControllers or Pawns get assigned to the clients, and it looks like the server has lost connection with them. The code looks like this:
AWLobbyGameMode::AWLobbyGameMode(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
this->bDelayedStart = true;
PlayerControllerClass = AWLobbyPlayerController::StaticClass();
DefaultPawnClass = ACharacter::StaticClass();
PlayerStateClass = AWLobbyPlayerState::StaticClass();
GameStateClass = AGameState::StaticClass();
}
bool AWLobbyGameMode::ReadyToStartMatch()
{
return AreAllPlayersReady();
}
void AWLobbyGameMode::StartMatch()
{
Super::StartMatch();
FString UrlString = TEXT("/Game/Maps/MyMap");
GetWorld()->ServerTravel(UrlString);
}
APlayerController* AWLobbyGameMode::Login(UPlayer* NewPlayer, const FString& Portal, const FString& Options, const TSharedPtr<FUniqueNetId>& UniqueId, FString& ErrorMessage)
{
APlayerController* pc = Super::Login(NewPlayer, Portal, Options, UniqueId, ErrorMessage);
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, pc->PlayerState->PlayerName);
return pc;
}
bool AWLobbyGameMode::AreAllPlayersReady()
{
if (GameState->PlayerArray.Num() <= 0) return false;
for (int i = 0; i < GameState->PlayerArray.Num(); ++i)
{
AWLobbyPlayerState* state = Cast<AWLobbyPlayerState>(GameState->PlayerArray[i]);
if (!state->bIsReady)
{
return false;
}
}
FString str = (HasAuthority() ? "Server: " : "Client: ");
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Green, str + "All players are ready");
return true;
}
Any ideas? Also worth asking; do I need to use seamless travel?