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