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).
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…
Client chooses a color locally and calls a server RPC (either through the pawn or the player controller)
The server RPC then calls a multicast RPC with the color index.
The multicast RPC sets the material
An RPC + RepNotify solution might look something like this…
Client chooses a color locally and calls a server RPC (either through the pawn or the player controller)
The server RPC sets a color index (let’s say ColorIdx) variable which is marked RepNotify
Inside the OnRep_ColorIdx function you set the material