MultiCast to Clients ends in Remote Switch

Hey there,
this might be a common question, but i didn’t find any solution yet.

The client presses a button to change the color (material) of the player. Locally (without RPCs) it works just fine. Now i want that in a Multiplayer logic, that every client gets informed, which color is used and deactivate the buttons afterward and release them, if they’re free again (logic not implemented yet).



What am I missing?

Thanks in advance.
Best regards

Touch3x

There might be more thing because this is a lot to untangle but there are some thing I see from the start…

On your first BP:
GetPlayerController with Player Index 0 - The server has all player controllers so this logic will only change the color of one of them. On clicked pass the controller as a parameter to the Server Select Color.

On your second BP:
You have to move this in the pawn and loose the Switch Has Authority. You want the pawn to change color on all clients including the ones that are not controlling it. (I assume) However the clients don’t have other controllers except their own. They gave the pawns though and the server can call the Multicast Change Color inside the correct pawn of all clients.

It can be difficult to follow code snippets so I’ll refrain from commenting directly on how you should change the code you posted and focus more on the theory.

Material changes are not something that is replicated so any change you want to make you need to make on all clients (including the server). There are 2 main ways you could go about this. One is using RPCs and the other is a combination of RPC and RepNotify. An RPC solution might look something like this…

  1. Client chooses a color locally and calls a server RPC (either through the pawn or the player controller)
  2. The server RPC then calls a multicast RPC with the color index.
  3. The multicast RPC sets the material

An RPC + RepNotify solution might look something like this…

  1. Client chooses a color locally and calls a server RPC (either through the pawn or the player controller)
  2. The server RPC sets a color index (let’s say ColorIdx) variable which is marked RepNotify
  3. Inside the OnRep_ColorIdx function you set the material