x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

PlayerController/PlayerState different on client and server.

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.

Product Version: UE 4.9
Tags:
more ▼

asked Nov 04 '15 at 08:13 PM in Using UE4

avatar image

DeadMetal4
1 1 2 3

avatar image Stunt Thumper Nov 05 '15 at 05:42 PM

How is someone supposed to help you without seeing BPs or code?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

PlayerControllers do not replicate, hence player controller on the serverside and client side are dfferent ones.

"If i understand correctly the PlayerController exists on the server and the owning client which is what I want," This isn't correct , PlayerController exist locally on each machine with it's own id. if you get player controller with id of 0. You will always return the local player ( unless it's a splitscreen ).

more ▼

answered Nov 05 '15 at 08:17 PM

avatar image

Frozenfire
662 61 84 117

avatar image DeadMetal4 Nov 05 '15 at 08:32 PM

Alright, that makes more sense for what is going on. If I wanted a local player controller to have the same data(i.e. pointers to actors) as the one that exists on the server is that when I need to use replication for these references?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question