I am trying to create a multiplayer game and I have run into this problem. I set some data in the player controllers and have them possess pawns OnPostLogin in my Custom GameMode. I can see this data for both players (server and client) while viewing the server window. However on the client window this data is no longer there. Upon further investigation I have noticed that the server has instances of playerController_1 and playerController_2 but the Client has playerController_3. If i understand correctly the PlayerController exists on the server and the owning client which is what I want, but I want the client to have the same PlayerController that I initialized the data for in my game mode OnPostLogin.
I also looped through the PlayerStates that the client sees opposed to the server. The server has playerState_1 and playerState_2 while the client has playerState_3 and playerState_4. I was under the impression the same player state with the same data would be replicated to all clients.
I have read as much as I can find on replication and the framework for unreal but I am still a novice, any insight regarding what is happening here would be helpful.
Thanks in advance.
EDIT
I have solved some of the problems. Regarding the player state issue, I was not replicating the values correctly I had forgotten this.
void AMatchPlayerState::GetLifetimeReplicatedProps(TArray< FLifetimeProperty > & OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
DOREPLIFETIME(AMatchPlayerState, playerHandSize);
DOREPLIFETIME(AMatchPlayerState, spellDeckSize);
}
After fixing that with the player state I tested replicating simple variables on my player controller. The data did get passed to the clients when I did it this way. So I think I have pinpointed my problem, replicating pointers to Actors that are located in my PlayerController.
CustomPlayerController.h
UPROPERTY(BluePrintReadWrite, Replicated)
ASpellDeck* spellDeck;
UPROPERTY(BluePrintReadWrite, Replicated)
APlayerHand* playerHand;
CustomPlayerController.cpp
ACustomPlayerController::ACustomPlayerController()
{
bReplicates = true;
bAlwaysRelevant = true;
}
void ACustomPlayerController::GetLifetimeReplicatedProps(TArray< FLifetimeProperty > & OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
DOREPLIFETIME(APlayerControllerMatch, spellDeck);
DOREPLIFETIME(APlayerControllerMatch, playerHand);
}
void ACustomPlayerController::ServerSpawnHand_Implementation()
{
FActorSpawnParameters SpawnParameters;
SpawnParameters.Owner = this;
playerHand = GetWorld()->SpawnActor<APlayerHand>(SpawnParameters);
}
bool ACustomPlayerController::ServerSpawnHand_Validate()
{
return true;
}
void ACustomPlayerController::ServerSpawnDeck_Implementation()
{
FActorSpawnParameters SpawnParameters;
SpawnParameters.Owner = this;
spellDeck = GetWorld()->SpawnActor<ASpellDeck>(SpawnParameters);
}
bool ACustomPlayerController::ServerSpawnDeck_Validate()
{
return true;
}
//this is called after PostLogin in the game mode.
void ACustomPlayerController::InitializeGameComponents()
{
if (!spellDeck)
{
ServerSpawnDeck();
}
if (!playerHand)
{
ServerSpawnHand();
}
}
When I check the value of playerHand or spellDeck for the client the value is null.