A really dirty solution is to add a delay before change state to spectating after set bIsSpectator to true.
Code:
void ASPlayerController::SetSpectatorState() { PlayerState->bIsSpectator = true; // Waiting IsSpectator replication before set state spectating FTimerHandle TimerHandle_Tmp; GetWorldTimerManager().SetTimer(TimerHandle_Tmp, this, &ASPlayerController::WaitingForChangeState, 3.f, false); } void ASPlayerController::WaitingForChangeState() { ChangeState(NAME_Spectating); ClientGotoState(NAME_Spectating); }
Another solution would be, in the OnRep_IsSpectator, the client tell the server to set him state spectating. I haven't test it at this time. But I'm not sure the replication of bIsSpectator is the real or only cause.
Leave a comment: