How do I replicate a material from an object on the server to the corresponding object on the client?

To anyone finding this a year later, like me ; )

I had the same problem, to replicate a material to my clients, only in my case I used a UMaterialInterface* myMaterial on the server. Simply replicating this to my clients didn’t do anything.

The problem is the same with an Actor’s rotation, or location, or anything. These values are replicated, but they aren’t actively set, which means the “SetMaterial” or “SetRotation” or “SetLocation” has to be called when the material changes.

I imagine this is what RepNotify is for exactly, because if you create this event on replication:

UPROPERTY(ReplicatedUsing = OnRep_SetMaterial)
UMaterialInterface* myMaterial;
UFUNCTION()
virtual void OnRep_SetMaterial();

… and then in the cpp you add “myMaterial” in the DOREPLIFETIME Macro along with all your other variables, and implement:

void AAnyActor::OnRep_SetMaterial(){
// this now actively sets the material, and it shows up on the clients
this->Mesh->SetMaterial(0,myMaterial);
}

At least this works perfect for me : )

2 Likes