Change and Sync Color on Multiplayer

Hello! I’ve been trying to follow numerous tutorials on Youtube on how to set up a realtime material changer in Unreal, and I’ve gotten really close! However, since I’m fairly new to Unreal and to Multiplayer, I can’t seem to figure this out no matter what methods I choose (multi-cast, repnotify, ect.) So far I am only able to change the color of the dresser on the server and replicate it on the clients screen, but if I change the color on the clients screen, it doesn’t replicate it back to the server? I have class defaults set to replicate, and tried setting authority as well…

Any help would be greatly appreciated!

Dresser Blueprint

Widget Blueprint that has a button that the character can click to assign the new material

Hi, AFAIK only way for the client to tell the server something is via RunOnServer events (which means client asking the server to execute that logic on the server). And only the client that owns that actor can call a RunOnServer event on that actor. If any other client tries to do so, nothing will happen.

Also you can only change the owner on the server. That means, that it would make no sense to have RunOnServer events on actors where you expect different clients to use them, since you would then need to change owner what you can only do on the server.

That means you need to shift the RunOnServer event to something that you know the client will own during the whole game (e. g. the player controller or the controlled pawn). So for example OnClicked in the widget → calls event inside the player controller → RunOnServer → calls event on your actor to change color → replicate change to all clients (I would use repnotify here instead of multicast, since if the client missed the multicast (e. g. dropped if its not reliable due to bandwidth, network relevancy, in progress join) it will never get the change which then means that you shouldn’t use multicast for persistant changes but only for one shot events).

Okay, I think I get what you’re saying! So I should actually switch my material changer to be on the character controller instead of the BP actor? And have the Clicked_Boeing?>RunOnServer>Set Material (and then use the material instance as the repnotify to change the material)?

The only reason why I was doing it this way is because I have a ton of different BP actors that will have this same functionality, and figured this would be a cleaner/easier way to do it for creating an interactive ArchViz project that’s multiplayer.

I’m still having a hard time figuring out how to set up repnotify functions but I think I got it to work ealier, will post screenshots of it when I get it setup again.

I greatly appreciate the help and input!

So I should actually switch my
material changer to be on the
character controller instead of the BP
actor?

Not sure I understand you correctly. You directly send the client player input to the server (e. g. from the widget click event send it to the player controller and from that to the server) and then handle the rest on the server. So the server would then (inside the player controller) call the material change logic that you currently have in your widget. The actual material change logic should still be in the actor, to not cramp the player contoller. The idea is that you just send all client inputs that are game relevant (everything you want the server to know about) directly to the server.

And have the
Clicked_Boeing?>RunOnServer>Set
Material (and then use the material
instance as the repnotify to change
the material)?

Sounds good.

because I have a ton of different BP
actors that will have this same
functionality

Use inheritance or an interface?

Okay! Thank you so much! I think I finally got it thanks to your help! Though I am sure there is a much quicker/condescend way of doing this haha… At least it’s finally communicating back and forth! Now I just have to repeat this for like 80 more assets… oh boy. If you know of any possible way I can condense this, that would be so helpbul! (I tried a multi-gate with only one Multicast input going in on the Arch_Viz_Character, but that just cycled through the materials instead of the one that was selected. Here is what I’ve got working so far:

Now I just have to repeat this for
like 80 more assets… oh boy.

Yes, you really need to do it in a different way than what you currently have =)

If you know of any possible way I can
condense this, that would be so
helpbul!

Can you explain what you’re trying to achieve?

But if I understand your logic correctly, then you click on a button and then you change the material of a “jackie_dresser_BP”. And depending on what button you’ve clicked you want a different material.

If I understood that correctly, then you only need one event (one event that gets called from the widget that then calls a RunOnServer event) inside the character and one event inside the “jackie_dresser_BP” which will get called from the RunOnServer event of the character.

In order for this to work with one event you need to pass either the new material with that event or something else that you can uniquely associate with a material (e. g. an enum and then inside the “jackie_dresser_BP” use a map from that enum to the material you want).

I’ll continue in the next comment since AH doesn’t like too long comments and tends to block them into moderation queue…

So you keep On Clicked “Boing_Navy”, On Clicked “Cessna_Gray”… all those inside the widget but instead of having ClickedBoing?, ClickedCessna?.. you only have one Clicked event. This one Clicked event then also needs a reference to the material you want to use or the enum value (depending on which you way you want to do it).

Lets assume you use an enum. I would name the elements of the enum like “Boing_Navy”, “Cessna_Gray”, …

So for example if you click the On Clicked “Boing_Navy”, then you call the Clicked event and use the enum value “Boing_Navy” as input.

Now in your “jackie_dresser_BP” you also only need one event (e. g. lets call it “ChangeMaterial”) instead of having “SetBoing”, “SetCessna”,… This one “ChangeMaterial” event would then again need either a material or enum value as input (since above I described it with an enum, use an enum as input).

So from the Clicked event inside the character you still do the SwitchHasAuthority part, and then call the “ChangeMaterial” event inside the “jackie_dresser_BP” and just pass the enum value ´from the Clicked event into that event.

Now you also need a way to get the material you want to use from the enum value. For that you create a map variable inside the “jackie_dresser_BP” and let it map from the enum (so from “Boing_Navy”, “Cessna_Gray”, …) to a material reference (the material you want to use for Boing_Navy, Cessna_Gray,…).

Then from the “ChangeMaterial” event inside the “jackie_dresser_BP” you get the material reference from the map using the enum value. Now if you would have single player, then you could just apply that material that you get (like you do it in all your OnRep functions but again you will only need one) and be done.

But since this should work in multiplayer you need to tell the other clients about the new material. So you can create a new repnotify material reference variable (like you’ve done with “Boing Navy”, “Cessna Gray”, … but you will again only need this one variable) and set that. Then inside the RepNotify function of that variable you apply it to the meshes.

Alright, I am lost, but I am sure with some re-reading and looking up tutorials on enums and such, I will better understand lol.

But from what I can tell, you are explaining exactly what I want. I guess just a quick run-down of it, I’m creating an interactive multiplayer ArchViz walkthrough. And when a player’s cursor “clicks” on a piece of furniture, it brings up it’s own widget with the different types of materials that that product has, and each will be able to be previewed in real time depending on what the client chooses. So what I have set up right now as a testing area, is 4 separate BP Actors that have their own unique Widgets since each are offered in different materials. Then when I get these 4 set-up properly I can hopefully copy/paste it to the remaining assets (of course re-assigning values and such).

Again, I appreciate the help and will update when I get further along on understanding/implementing what you explained above!