Description

APlayerController::ClientStartOnlineSession() checks PlayerState at the start of a game after loading a level. Due to time needed to load in, client player state may may return NULL

Steps to Reproduce

1. Open source version of editor (third person template)
2. Create custom GameMode class (MyGameMode)
3. In APlayerController.cpp add #include "Engine.h" as well as debug message to ClientStartOnlineSession_Implementation()

GEngine->AddOnScreenDebugMessage(-1, 20.0f, FColor::Cyan, TEXT("APlayerController::ClientStartOnlineSession_Implementation"));
 
     if (PlayerState == NULL)
     {
         GEngine->AddOnScreenDebugMessage(-1, 20.0f, FColor::Cyan, TEXT("PlayerState == NULL"));
     }

4. In MyGameMode.h add override statement for PostLogin() function

void PostLogin(APlayerController* NewPlayer) override;

5. In MyGameMode.cpp add the following:

void AMyGameMode::PostLogin(APlayerController* NewPlayer)
{
	GEngine->AddOnScreenDebugMessage(-1, 20.0f, FColor::Cyan, TEXT("ABugTestProjectGameMode::PostLogin"));

	Super::PostLogin(NewPlayer);

	if (!NewPlayer->IsLocalController())
	{
		NewPlayer->ClientStartOnlineSession();
	}
}

5. Compile
6. In the editor, click the drop down next to Play and select Advanced Settings
7. Set Number of Players to 2, Uncheck "Use Single Process"
8. Set Editor Multiplayer Mode to "Play As Listen Server"
9. Launch in standalone

Result:
The client window will show the playerstart has not been set yet (PlayerState == NULL)

Have Comments or More Details?

Head over to the existing Questions & Answers thread and let us know what's up.

0
Login to Vote

Cannot Reproduce
ComponentUE - Networking
Affects Versions4.8.3
CreatedJul 31, 2015
ResolvedApr 26, 2016
UpdatedJul 14, 2021