Problems with replicating dynamic material

Edit 3: I am now creating the deck entirely in blueprints. I call a BlueprintImplementableEvent in C++ to create the deck. It goes through a For loop, creating each card. Every time the index changes I set a variable to the new index (the index number controls the scalar parameter to set the texture of the card material). The index is RepNotify so it calls a function to then set the material. Once again, it doesn’t work on the client. I’m thinking the problem might be elsewhere.


Edit 2: I managed to get rid of the LogNetPackageMap warnings by creating a blueprint of the card, setting up the dynamic material in the construction script of the card’s blueprint, and then spawning the blueprint cards in C++. However, I still can’t manage to replicate the material. I tried making a multicast function in blueprints themselves via a BlueprintImplementableEvent that got called first, Repnotify in C++, and Multicast in C++. They always update on the listen server, but never on the client. I still have no idea what’s wrong.


Edit 1: I have discovered from this question that my material must not be net addressable because it is created at runtime. I get one of these warnings for each card:
LogNetPackageMap:Warning: UPackageMapClient::SupportsObject /Game/UEDPIE_1_level1.level1:PersistentLevel.SCard_145.CardComp1.MaterialInstanceDynamic_415 NOT Supported.Not RF_WasLoaded. NetGUID: <0>

I guess now my question becomes: How do I make my material net addressable? The answer on the other thread was to pass the texture as a parameter via an RPC function. However, the server should be telling the client to update the material, not the other way around. Why would an RPC function work and not a plain old repnotify or a multicast? I am quite confused.


I have a deck of cards where each card has a dynamic material associated with it. The texture of this material changes depending on what card it is, ie. Ace of Spades, 2 of Diamonds, etc. The problem is that the updates to the material are not getting replicated. On the listen server, all the cards look as expected, but the client shows nothing but 2 of Spades, which is the first card in the texture.

I have replicated every relevant variable in the Card class as well as the GameMode class where the deck actually gets created.

My repnotify function looks like this:

 void AMyGameMode::UpdateCardMID() {
      Deck[CardIndex]->TheMaterialMID->SetScalarParameterValue(FName("Card"), MIDvalue);
 }

Deck, CardIndex, TheMaterialMID, and MIDvalue are all replicated. MIDvalue (which tells the material the texture coordinates to use) has UPROPERTY(ReplicateUsing = UpdateCardMID) which I remember to call after MIDvalue changes.

I’ve also added all these replicated variables to the GetLifetimeReplicatedProps function in their relevant classes.

The repnotify method is what I’m doing currently. I have also tried multicast replication but that didn’t work either. I could really use some help if anyone has an idea what the problem is.

I finally figured this out. First, I was trying to setup the repnotify or the multicast in the GameMode instead of the Card object itself, ie. I was trying to change the card’s material within the GameMode instead of the Card. I guess if you want to change an object’s material you can’t do it outside of the object? In any case, I created a variable inside of the Card object that controls the Scalar Parameter of its dynamic material. This variable is RepNotify. I set this variable in the GameMode, but the repnotify function itself resides within the Card.

Another thing I found by looking at the networking Content Examples, specifically the street light, is that neither the StaticMesh, nor the materials are replicated. I was pretty much replicating everything to make this work, but I found that if the material is replicated, then it actually stopped working.

Not sure if it this was a result of quirks in my own set up or not, but it worked for me.

Can you please post the final working code?

You’re a life-saver. Thanks.