Replicating Components on Blueprints
Based on the ShooterGame sample, I created a new weapon (via Blueprint). It's a weapon that changes its color (among other things, but irrelevant right now) based on whether it's hit by sunlight or not.
Skipping the details, the functionality is working, but the change is only visible on the local machine (server or client). I want it to be replicated.
So, I have the following setup... here's the construction script.
Here's the event graph (only the relevant part):
I tried setting the property "Replication" to "Replicated" on the variables Material1P and Material3P (I know, only really needed on Material3P), but then the change only happens on the server, and not on the client(s). The Timeline also has "Replicated" checked.
I also tried changing the Mesh1P and Mesh3P declaration:
Didn't help too. Ideas?
asked Mar 11 '14 at 02:53 AM in Blueprint Scripting
ue4-archive ♦♦ STAFF
Hi, there is a lot going on here!
You are on the right path I think. For something like this, it is best to replicate the state w/ a bool like IsSunLit and handle material swaps in the rep notify. Dynamic materials cannot be replicated in the way you were trying in your original post. You are best to do this all at a higher level and have client side code do the actual material swap.
My question is - who is setting IsSunlit? Ideally the server is in complete control of IsSunLit on everybody's weapon. When the server sets IsSunlit, it reps down to everyone else and everyone does the material swap. What it sounds like what is happening is you are setting IsSunlit in some code that is being run on the local client machine. IsSunLit will not replicated client -> server. If IsSunlit has to be set on the client, then like you suggest in your last post, you need to send a server RPC to the server, telling him to change IsSunlit to the new value. Then all the server does is call Set w/ Notify on IsSunLit and everyone gets the new value and does the material swap. (so, like I said, I think you are close: If ServerSetWeapon3PScalarMaterialInstance is really necessary, then it should just set IsSunlit, and the material change should happen in the RepNotify)
Does that make sense?
To answer your other question - don't do a RemoteRole < 2 check. You can use the "Switch Has Authority" macro in blueprints for determining if the local machine is the authority (server).
It's a little difficult for me to put together a totally valid answer, because I'm pretty new to UE4 still, but I imagine that replication still works mostly like it always has -- in the past, only Actors and their subclasses were directly replicateable to clients. If the component chain still works the same way as it used to, *Component are not Actors, and therefore they do not get replicated and auto-created on the client ends.
From a UE3 perspective, what I would do, is replicate a variable that points to the package blueprint being used for the component, and then when that variable is received on the clients ends, then you know that you need to change out the Mesh components locally.
Not sure if that makes sense. :-S
Follow this question
Once you sign in you will be able to subscribe for any updates here