Replicated variable delayed?

I have spent quite a while scouring the web for a better solution then I have so far to deal with one of my variables not replicating when I need it to.

The important bit is in my player controller class here:

When I attempt to utilize the Char Select Data Array variable in the Player Controller here it is not replicated on the client yet(but if I run it again I get the replicated data from the prior execute):

The fix(below) is to manually create a copy of the array to pass the data into the client RPC which mostly eliminates the whole point of the replicated variable. what am I missing to make the client RPC execution wait until the variable has been updated?

1 Like

Looks like you need a RepNotify

If you set the array to RepNotify, you’ll get a function that gets called on the client when the value changes, no need to call an RPC.

My understanding is that a RepNotify is “When this variable is changed on the authority(Server) do this:”
In the case of this array, I will not always do the same thing after every time this value is adjusted. For example, the array is appended with a for each loop. My understanding is that each time the loop adds an item it will then call the repnotify function which is wasteful if I don’t want it to do anything until the array is fully built.

If I am further working around on this, I’d have to create a new bool value that is tracked and set that the rep notify casts to when checking if done, which might need to be replicated to achieve the same result putting me right back where I started?

This shouldn’t be a new issue, I guess my question is when does the variable actually replicate and how do we control the flow to be dependent on this replication since the blueprint logic does not seem to be intuitive to multiplayer. As my example illustrates; creating a new array forces the flow while setting a replicated variable does not.

While I might be able to alter my set-up to use Rep-notify to trigger my next set of instructions on this particular situation, I will not always want to execute the same task each time a variable is updated. My understanding of RepNotify is: “Every time replicated variable is changed do: X” Sometimes I will not want to do X, and writing in logic for every single instance where the variable changes to find out which set of instructions to use does not seem reasonable.

Isn’t the whole point of setting a veritable as “replicated” is to make sure that the client and server reach parity? If you draw a pin from a set variable on a server event to a RPC then the server is setting the variable before the client is even being told to run it’s event. My assumption is that there is a “Stack” or “stream” of instructions to be shipped to the client and the replication adjustment should be in front of the clients event execution call.

This apparently is not the case, and I have a hard time accepting replication as an option is non functional even marked as “reliable.” I have got to be missing something critical about replication that is not in the documentation or in the Amazingly useful Cedric’s UE4 Networking Compendium

AFAIK RPCs and property replication are independent systems and don’t offer any ordering guarantees between them.

Appending to a RepNotify array in a for loop might (I haven’t checked) call the RepNotify every time on the server, but not the client as replication as the array would only be replicated at the end of a frame (after the for loop as finished).

If you need to do different things with the array at different times when it gets replicated then your approach of sending the array as a parameter makes sense to me, you could stop replicating the array and just set it locally in each of your RPCs

After some discussion in a discord with other devs I have determined passing values as parameters will be the go to moving forward, just as you noted. Just wanted to return and close this out.

Glad you got it sorted!

I have exactly same problem and i dont think passing values as parameters work for mine. This problem is really boring.

This is an old thread, but just in case it helps someone else in the future. I could not swap my method as it would have to be a full rebuild. This may just be a temporary solution as I think I am going to rebuild at some point with a request/response set up for everything, but for now I just created events to call that “DelayUntilNextFrame” and then call the logic that requires the updated variables. As long as you mark the server calls as “reliable”, this ensures you are getting the updated values properly.