But I’m struggling to understand how to apply that logic to SetStaticMesh() in a UStaticMeshComponent. If I try the same setup using the code below, then the players all disappear from each others’ viewports (???)
Solved. Some takeaways for posterity:
Even if the component is replicated, SetStaticMesh() will not replicate. I had to make and call a function on the ACharacter that owned the component instead. Code in the UStaticMeshComponent derived class:
You seem to have jumped through a few hoops here. The Static Mesh Component, when replicated, will replicate the change of a static mesh.
Replication however is one-directional - it only ever goes from Server->Client. A Client cannot change the mesh and then propagate that to all other clients. They must ask the Server to do so via an RPC. Components can call RPC’s so long as the player owns the components actor and the component is replicated.
The client also needs to be the “Owner” of the object which has the replicated mesh component, since you cannot call RPC’s on an object you do not own.
If you are not the owner, then you have to pass the RPC through an object you do own (e.g, the player controller, player state or pawn).
You’re correct, the problem was the one-way nature of the replication. I tried to do it all within the component itself, but I was getting a very weird effect where all the **other **clients would disappear off each others’ screens. The leap to pushing it up into the owning character was a desperate measure.
Thanks for your reply though, I might try that and see if I get some better results than I was before. Cheers!
Yep, I just tried that code and it has the same effect. Calling SetStaticMesh() from within the component as the Authority will make every other player disappear off your screen and off each other’s. Bizarre.