Announcement

Collapse
No announcement yet.

How to use APlayerState::CopyProperties with seamless travel?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to use APlayerState::CopyProperties with seamless travel?

    Hey, I'm working on an asymmetrical game (similar to dead by daylight), and I want to transfer the player's role (enum) from the lobby to the game level. This role is used to determine which character to spawn for the player in the game level.

    Is the copy process supposed to be a "two stop" logic? So I should copy first from Lobby to Transition Map, and then Transition Map to Gameplay Map? Because right now, I'm handling this as going from Lobby to Gameplay Map.

    Here is the code, no errors, but the role is not transfered. Seamless travel is enabled on the lobby GameMode, and I've been testing it in Standalone mode. Thanks in advance!
    Code:
    UPROPERTY(Replicated, BlueprintReadOnly)
    EPlayerRole PlayerRole;
    Code:
    void AHGameplayPlayerState::CopyProperties(APlayerState* PlayerState)
    {
         Super::CopyProperties(PlayerState);
    
         AHLobbyPlayerState* PS = Cast<AHLobbyPlayerState>(PlayerState);
         if (ensure(PS))
         {
              PlayerRole = PS->PlayerRole;
         }
    }
    
    void AHGameplayPlayerState::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
    {
         Super::GetLifetimeReplicatedProps(OutLifetimeProps);
    
         DOREPLIFETIME(AHGameplayPlayerState, PlayerRole);
    }

    #2
    It's the other way around - CopyProperties is called on the old PlayerState, and the incoming argument is the new PlayerState.

    Take a look at APlayerState::SeamlessTravelTo

    Comment


      #3
      TheJamsh Sweet, it is working as expected now. Thank you so much!

      Comment


        #4
        NP's - I had to check myself Not the most obvious of function/parameter names..

        Comment


          #5
          TheJamsh Can you answer me one more question real quick? Since seamless travel doesn't disconnect players, how can I track if everyone is finished transitioning into the game level? Should I run a PlayerController iterator every second or so?

          Edit: In GameModeBase I found the HandleSeamlessTravelPlayer method. As far as I understand this initializes the player after seamless traveling, so I think this will suffice.
          Last edited by STRiFE.x; 08-04-2020, 05:47 AM.

          Comment


            #6
            Sure - AGameModeBase has a NumTravellingPlayers property (or something like that) you can check Server-side, to check if it's still waiting for clients to transition into the map.

            Comment


              #7
              TheJamsh Yeah, it is in AGameMode though, I'll reimplement it or come up with something else. One thing that I still find weird, is that the widgets stay on the screen after seamless traveling. Shouldn't they get destroyed with the HUD class?

              Comment

              Working...
              X