Ah I did not know about any of that function
Here is how I did that, and now the Host/ListenServer does indeed remain correct. However the value is not replicated for the client.
void APuzzPlatPlayerState::GetLifetimeReplicatedProps(TArray< FLifetimeProperty >& OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
DOREPLIFETIME(APuzzPlatPlayerState, CurrentTeam); //WHY DOES THIS GIVE ERROR?
}
void APuzzPlatPlayerState::CopyProperties(APlayerState* PlayerState)
{
Super::CopyProperties(PlayerState);
UE_LOG(LogTemp, Warning, TEXT("Copying Properties YEAHBOIIIII"));
APuzzPlatPlayerState* pState=Cast<APuzzPlatPlayerState>(PlayerState);
pState->CurrentTeam=CurrentTeam;
}
As you can see I override the GetLifetimeReplicatedProps
function, but the line where I try to use the DOREPLIFETIME macro on my CurrentTeam variable always gives me an error (it says “Type name is not allowed” for my first argument, and also it tells me DOREPLIFETIME is undefined.
In the header I have put
public:
UPROPERTY(replicated)
int CurrentTeam = 111;
protected:
void GetLifetimeReplicatedProps(TArray< FLifetimeProperty >& OutLifetimeProps) const override;
The error log reads like this:
1>C:\Users\Documents\Unreal Projects\3_Steam_Multiplayer-master\UnrealProject\PuzzlePlatforms\Source\PuzzlePlatforms\PuzzPlatPlayerState.cpp(10): error C2275: 'APuzzPlatPlayerState': illegal use of this type as an expression
1>C:\Users\Documents\Unreal Projects\3_Steam_Multiplayer-master\UnrealProject\PuzzlePlatforms\Source\PuzzlePlatforms\PuzzPlatPlayerState.cpp(10): error C3861: 'DOREPLIFETIME': identifier not found
I have undated the Github project in case you wish to look at the whole project: c0de-m0nk3y/AirHockeySteam (github.com)
(I truly think this one last thing ie. the replication of that one variable CurrentTeam
will be enough for me to make massive strides after I figure it out. I will leave the code alone for a little while as I ran out of ideas and don’t want to remove correct code or add any more incorrect code.)