Download

Multiplayer ClientInstance<>Server Replication File

Good morning guys

Is there any built-in class which replicates between the server and client only? Meaning, Player State is replicated across all clients, so all players could technically have access to other player’s info on said classes. What I’m looking for is something which is only replicated between Client and Server, and independent of the ACharacter class (as this only exists when the player is alive, right? When the player dies or goes into spectating, this stops existing). PlayerControllers could be a good option, but they too can be a bad choice, as a normal MP game would typically have 2 PlayerControllers (Spectating & Playing).

So, you want a special class that only replicates to the Owning Client? The easiest way to achieve this is to just replicate the relevant properties of an object using the DOREPLIFETIME_CONDITION macro. Here’s an example, used in ‘GetLifetimeReplicatedProps()’:



DOREPLIFETIME_CONDITION(AMyClass, bMyBool, COND_OwnerOnly);


The above means that that particular replicated variable will only be sent from the server to the owning client, other clients will be ignored. AFAIK there’s no way to set this on an entire ‘class’ since objects only have a few defined ‘roles’, but replicating the properties like this is the easiest way to achieve it, and gives you maximum flexibility.

There are a bunch of conditions you can use, including custom-created ones. See here:

Also it’s worth noting, just because the PlayerStates are replicated, the only properties that replicate in the PlayerState from the Server are still the ones that are marked for replication. Only properties marked for replication are replicated.

Serves my purpose! Thanks!

Additionally, I have some data that I only want to be loaded once - since its heavy - and before the player actually enters the game, for performance reasons. How/where can I load it before the game itself loads (player enters the game) and where can I store/access it?