Multiplayer C++ PlayerState Not Working

Please see the attached minimal sample that demonstrates the problem. I have tested this in both 4.13.2 and 4.14.0 and it fails in both cases.

Open the sample project and compile. Then run with 2 clients.
Click the Host button on the first client and let it load into the lobby. You should see your player name displayed.
Now click the Join button on the second client and wait (for a while). Once it loads into the lobby you should see your player name twice (obviously cause your running it from the same computer) on both client 1 and client 2.

Now close it all down and open the CodePlayerState in the project in Visual Studio. Uncomment the “replicated” part of the variable in CodePlayerState.h and then uncomment the 4 lines in CodePlayerState.cpp. Now compile. I find it best to close the editor before compiling as the hot reload usually crashes the editor.

Once compiled, open the project up and run it again with two clients and follow the same steps as before. However notice this time that client 1 (the host) shows the two names per normal, while client 2 (the one that joins the session) shows nothing. My testing has worked out that as soon as you add a replicated variable to a C++ player state, it seems to break the player state replication completely. You can add replicated variables to a blueprint player state without a problem. It is just a C++ player state that breaks.

Now either I’m doing something really stupid or there is a bug. I’m suspecting the latter.

Hey wilberolive,

I’ve looked at your project, and what you’ll need to do is add a call to your parent function GetLifetimeReplicatedProps inside of the function, so it should look like this:

void ACodePlayerState::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const

	DOREPLIFETIME(ACodePlayerState, MyMember);

After doing this, it should replicate as expected.

Have a great day

Oh wow. I cannot believe I forgot to do that. I feel so dumb.