Still not working properly… I wonder if this can be done purely on blueprints.
Here my current implementation.
First of all, I realized I was creating material instances for 1st and 3rd person for every for every pawn, which is inefficient, as we don’t need to create a material instance dynamic for the first person material instance on another pawn (another client), as we’ll never see it.
So first thing was to create a Material Instance Dynamic on the first person material only if you’re the owner of the weapon. How to do this however, I’m not sure. I suppose you have to verify RemoteRole, right? What should it be? >2, ==1, etc…? This is my first question.
Ok. Now this may be relevant. The event “Is Sunlit Changed” is verified locally (I think), on the client. Here is the function signature:
UFUNCTION(BlueprintImplementableEvent, Category=Weapon)
void IsSunlitChanged(bool IsSunlit);
It is called from TickActor() when the weapon has moved from light to shadow or vice versa.
Now, I have created a boolean on the weapon blueprint, called “IsSunlit”, with replication set to RepNotify. So when the client’s weapon has moved from light/shadow, this variable is set, and the function OnRep_IsSunlit is called.
Here is my current implementation of OnRep_IsSunlit. Basically, I want to create a Material Instance Constant on the Mesh3P of the weapon, and set a scalar parameter.
The end result is that the server pawn’s weapon material is replicated to the clients, but the clients pawn’s weapon materials aren’t replicated between themselves or the server.
On the screenshot, the big screen is the server; the small ones are clients. All weapons should be yellow (yellow = IsSunlit; purple = not IsSunlit).
Second question: any suggestions on how to fix this?
Well, I’m still new to replication and UE4, so I’m kinda lost here.