Hi !
I’m working on a multiplayer game so I’m implementing all the fundations to the game.
Actually i’m facing a problem.
In my case, players have to choose a ‘class’ (Sentinel for exemple) that going to be saved in the PlayerState.
But one I run
GetWorld()->ServerTravel(MapName);
My players travels but when I’m on my new map all the data is erased.
But I’ve done this
Here is my header file
class AEONRECKONING_API ABasePlayerState : public APlayerState
{
GENERATED_BODY()
public:
ABasePlayerState();
void BeginPlay() override;
void CopyProperties(APlayerState *PlayerState);
void GetLifetimeReplicatedProps(TArray<FLifetimeProperty> &OutLifetimeProps) const override;
UPROPERTY(BlueprintReadOnly, Replicated)
class UBaseClass *CurrentClass;
};
and here is the c++ one
ABasePlayerState::ABasePlayerState()
{
PrimaryActorTick.bCanEverTick = false;
bReplicates = true;
bNetLoadOnClient = true;
bAlwaysRelevant = true;
}
void ABasePlayerState::BeginPlay()
{
Super::BeginPlay();
// log current class address
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, FString::Printf(TEXT("CurrentClass for player %s address is %p"), *GetFName().ToString(), CurrentClass));
}
void ABasePlayerState::CopyProperties(APlayerState *PlayerState)
{
Super::CopyProperties(PlayerState); // This is called so we preserve data chosen to be preserved by default
if (ABasePlayerState *NewPlayerState = Cast<ABasePlayerState>(PlayerState))
{
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Green, FString::Printf(TEXT("Copying properties for player %s, class %p"), *NewPlayerState->GetFName().ToString(), CurrentClass));
NewPlayerState->CurrentClass = CurrentClass;
}
}
void ABasePlayerState::GetLifetimeReplicatedProps(TArray<FLifetimeProperty> &OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
DOREPLIFETIME(ABasePlayerState, CurrentClass);
}
But in the CopyProperties function the CurrentClass value is nullptr whereas it’s defined if I do a check before the seamless travel
And in the new beginPlay it’s nullptr too
I really don’t understand why it’s not working as I’m following the doc and the previous topic here so if someone have any idea I’ll take it ahah !