Download

Different material replication based on client?

We’re developing a card game. Obviously, an important factor for this would be card meshes with the proper materials applied to them.
But this is a multiplayer card game, and we want to make sure that each player can only see their own cards until a card is played.
This means that the materials would need to be replicated in such a way that is different for each connected client, and then change to whatever the server states the card actually is as soon as it get played.

How can this sort of per-client network replication be achieved?

EDIT: And no, we don’t intend to simply “flip cards over”, as that’s not how this game works.

That’s it. Replicate the state the card can be in (Played, not played, selected, deselected, etc), perhaps in the form of an enum (1 byte in size, lightweight to replicate).
Attach an OnRep-function to the replication so the clients run a callback on every replication change.

Pseudo’ish code:

.h



UPROPERTY(ReplicatedUsing=OnRepCardStateUpdated)
    EMyCardStateEnum CurrentCardState;
UFUNCTION()
    void OnRepCardStateUpdated();


.cpp



AMyCardGame::OnRepCardStateChanged() {
	switch(CurrentCardState) {
		// decide what to do on each card state
		default:
			break;
	}
}


NOTE: Only the server may change this variable and replicate it to clients. You need to declare all replicated variables in your .cpp files with DOREPLIFETIME with or without conditions. Read up on the documentation for more info.