I’m attempting to change the colors of a material but the clients do not properly update. What am I missing? Can clients change the color of materials (client-side only of course) or only servers, and the servers tell the clients that the material was updated?
I am using a custom event that replicates to servers and clients (from GameState Event Graph) but it only calls on the server, is that possibly because I call “DoSpawnCharacters” func from Gamemode → GameState, then call the event “ChangeCharCols” from “DoSpawnCharacters” and have the custom event receive node in GameState’s Event Graph?
Not entirely sure. If someone could help, that’d be fantastic! I’m pretty new to UE4 but I’m willing to learn.
Executing spawning on the server is exactly correct, but you’ll have to use RepNotify for cosmetic changes as they aren’t replicated themselves.
Unfortunately, I don’t have access to our project right now. Basically, what you have to do is instead of setting the material/color directly on the server, change a variable that’s flagged as RepNotify (e.g. bSetColor or IsActivated or whatever). Then in reaction to the auto-created (client side) OnRep_ event , execute the color change.
In general, I found this video series extremely helpful:
Oh, odd. I tried doing a Custom Event and multicast it but it didn’t work. Using RepNotify did work entirely how I needed it to, but I might poke around seeing about Custom Events since setting a variable to RepNotify it instead seems a bit dirty to do. I’ll report back what I find out.
I’ll add a comment to this, I have a multicasted event in GameState’s Event Graph called “DoCharColors” which is called from a GameState function called “DoSpawnChars”, which “DoSpawnChars” is called from Gamemode which is of course server-side only. Is there any reason “DoCharColors” isn’t being called for all clients?
Hmm… I still have the Replication Tutorial (which I linked above) lying around, so I opened that project and tried replacing RepNotify for the bomb count to update the HUD with a multicast event (and making the count variable normal Replicated instead) and that worked.
I just tested again. It replicated fine for one part (decreasing the value during the game) but not for the initialization. Checking further I found that the initialization starts with a Switch Has Authority node and only continues for Authority. I’m not sure why that would make a difference. I certainly would have thought that doing the multicast from the server would always work, but apparently it doesn’t. Maybe you’re experiencing something similar.
All in all, it looks like the RepNotify method is more reliable after all. It’s also the recommended way:
Ooh okay. I watched through those tutorials a couple days ago but didn’t think that in my situation RepNotify was recommended to do, especially since it’s a bit odd to have to set a variable that is only ever used to do something server/client side and isn’t used for anything else.
While you’re here; I’ve got another networking issue that I don’t seem to understand that the videos don’t help with. Each PlayerController stores a variable, lives, which is replicated + public. How would I go about getting the value of lives for a certain PlayerController client-side?
The method I was thinking of was storing all PlayerControllers in a PlayerController variable array that was replicated, then cast to the CharController BP with a PlayerController from the variable array to then get the lives, but with some testing it seems to result in only getting the lives server-side or I’m doing something very wrong.
Maybe RepNotify is again what I need?
EDIT: Basically how would I pass all PlayerControllers to all clients, if they do not have them already? (Just to get values)
Yeah, we had the same problem. I don’t know if this is the “correct” solution, but what we ended up doing is store all PlayerControllers in an array in the GameMode. Each PlayerController also knows its own index in the array. (We currently assume the order never changes.) Then we can query all PlayerControllers’ properties by way of the GameMode.