# Change material color and update clients?

**URL:** <https://forums.unrealengine.com/t/change-material-color-and-update-clients/330357>\
**Category:** Rendering\
**Tags:** unreal-engine, UE4, Blueprint, question\
**Created:** [August 30, 2015, 2:43am UTC](https://forums.unrealengine.com/t/change-material-color-and-update-clients/330357 "2015-08-30T02:43:41Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Serfma\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Serfma\_1](https://forums.unrealengine.com/u/Serfma_1)\
**Post date:** [August 30, 2015, 2:43am UTC](https://forums.unrealengine.com/t/change-material-color-and-update-clients/330357/1 "2015-08-30T02:43:41Z")

</div>

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. 🙂

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_359f4d3c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_359f4d3c](https://forums.unrealengine.com/u/anonymous_user_359f4d3c)\
**Post date:** [August 30, 2015, 11:02am UTC](https://forums.unrealengine.com/t/change-material-color-and-update-clients/330357/2 "2015-08-30T11:02:29Z")

</div>

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:

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — https://unrealcommunity.wiki/! You will be able to find content from...

---

<div class="post-metadata">

**Author:** ![Serfma\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Serfma\_1](https://forums.unrealengine.com/u/Serfma_1)\
**Post date:** [August 30, 2015, 5:06pm UTC](https://forums.unrealengine.com/t/change-material-color-and-update-clients/330357/3 "2015-08-30T17:06:10Z")

</div>

Oh thank you so much! If I may ask, how come Custom Events being multicasted wouldn’t result in the same thing?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_359f4d3c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_359f4d3c](https://forums.unrealengine.com/u/anonymous_user_359f4d3c)\
**Post date:** [August 30, 2015, 6:44pm UTC](https://forums.unrealengine.com/t/change-material-color-and-update-clients/330357/4 "2015-08-30T18:44:25Z")

</div>

Huh, you’re right: That would also work!

I didn’t think to try this because when someone else asked the same question as you did, the recommended answer was to use _RepNotify_, and it worked for us when we had the problem.

It probably depends on whether there’s any variable that needs to be set anyway. (In our case we already had a fitting variable, so there was no extra work involved.)

Sorry if I ended up confusing you!

---

<div class="post-metadata">

**Author:** ![Serfma\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Serfma\_1](https://forums.unrealengine.com/u/Serfma_1)\
**Post date:** [August 30, 2015, 6:47pm UTC](https://forums.unrealengine.com/t/change-material-color-and-update-clients/330357/5 "2015-08-30T18:47:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Serfma\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Serfma\_1](https://forums.unrealengine.com/u/Serfma_1)\
**Post date:** [August 30, 2015, 6:58pm UTC](https://forums.unrealengine.com/t/change-material-color-and-update-clients/330357/6 "2015-08-30T18:58:42Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_359f4d3c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_359f4d3c](https://forums.unrealengine.com/u/anonymous_user_359f4d3c)\
**Post date:** [August 30, 2015, 7:31pm UTC](https://forums.unrealengine.com/t/change-material-color-and-update-clients/330357/7 "2015-08-30T19:31:01Z")

</div>

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:

> **[Content Examples](https://docs.unrealengine.com/5.2/en-US/content-examples-sample-project-for-unreal-engine/)**
>
> This sample project demonstrates specific concepts and techniques to use in Unreal Engine.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_359f4d3c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_359f4d3c](https://forums.unrealengine.com/u/anonymous_user_359f4d3c)\
**Post date:** [August 30, 2015, 7:34pm UTC](https://forums.unrealengine.com/t/change-material-color-and-update-clients/330357/8 "2015-08-30T19:34:54Z")

</div>

Incidentally, the above link refers to the _Content Examples_, which you can find under the launcher’s _Learn_ category.

You can find explanation/documentation for all examples here:

> **[Content Examples](https://docs.unrealengine.com/5.2/en-US/content-examples-sample-project-for-unreal-engine/)**
>
> This sample project demonstrates specific concepts and techniques to use in Unreal Engine.

---

<div class="post-metadata">

**Author:** ![Serfma\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Serfma\_1](https://forums.unrealengine.com/u/Serfma_1)\
**Post date:** [August 30, 2015, 7:49pm UTC](https://forums.unrealengine.com/t/change-material-color-and-update-clients/330357/9 "2015-08-30T19:49:49Z")

</div>

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. 😛

---

<div class="post-metadata">

**Author:** ![Serfma\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Serfma\_1](https://forums.unrealengine.com/u/Serfma_1)\
**Post date:** [August 30, 2015, 8:35pm UTC](https://forums.unrealengine.com/t/change-material-color-and-update-clients/330357/10 "2015-08-30T20:35:35Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_359f4d3c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_359f4d3c](https://forums.unrealengine.com/u/anonymous_user_359f4d3c)\
**Post date:** [August 31, 2015, 7:20am UTC](https://forums.unrealengine.com/t/change-material-color-and-update-clients/330357/11 "2015-08-31T07:20:58Z")

</div>

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.
