I have tested project multiple times now with four players and can report following findings:
- Sometimes, PlayerState is ok on all clients.
- Most of time, PlayerState is NULL on either one client or two of clients.
- PlayerState can also be NULL on all three clients (Occurs very rarely).
I also believe I know why PlayerState is sometimes NULL. At start of game, server will initialize everything, among PlayerState for all clients. PlayerState will eventually be replicated down to client. Also at startup, BeginSpectatingState function is called on all clients. If GetPawn() is not NULL, this function calls UnPossess which again calls GetPawn()->UnPossessed. This function sets PlayerState to NULL on client. If this call happens after PlayerState was replicated down to client, I believe client now sets its own PlayerState reference to NULL, which is why PlayerState is NULL on some of clients.
This is screen output I get:
When PlayerState is NULL, I get following screen output:
- ABugTestProjectCharacter::UnPossessed
- ABugTestProjectPlayerController::UnPossess
- GetPawn() != NULL
- ABugTestProjectPlayerController::BeginSpectatingState
- GetPawn() == NULL
- ABugTestProjectPlayerController::BeginSpectatingState
When PlayerState is ok, I get either this screen output:
- GetPawn() == NULL
- ABugTestProjectPlayerController::BeginSpectatingState
or this screen output (Same as first one):
- ABugTestProjectCharacter::UnPossessed
- ABugTestProjectPlayerController::UnPossess
- GetPawn() != NULL
- ABugTestProjectPlayerController::BeginSpectatingState
- GetPawn() == NULL
- ABugTestProjectPlayerController::BeginSpectatingState