I have a couple of replicated properties that I need to replicate in a particular order.
I have a property on my custom PlayerState (let’s call it “PropA”) and another property on a custom GameState (“PropB”). Both PropA and PropB are references to Actors. I have a function that runs in GameMode that first sets PropA and then sets PropB. When PropB is set, it triggers an “OnRep” event on clients that needs to use the value of PropA. Therefore PropA needs to have been replicated before PropB “OnRep” event is called. However, what I see is that PropB is replicated before PropA, so when my “OnRep” event is called the value of PropA is empty.
I’m trying to enforce replication order by adding a timer in my GameMode function after PropA is set to give it a chance to replicate, and the timer callback calls a function that sets PropB. However, I’m finding that I need to set an unreasonably long delay (around 1 second) to ensure that PropA is replicated before PropB. I would have thought that it would only take one or two Ticks for replication to happen.
My timer call is as follows: FTimerHandle timerhandle;
GetWorld()->GetTimerManager().SetTimer(timerhandle, this {CompleteGameStart(); }, 1.0f, false);
Thanks. I understand the order is not guaranteed, just surprised that I have to wait a whole 1 second for replication to take place (even using 0.5 sec didn’t work).
It’s a bit more complicated than I described in that different PlayerStates have different “PropA” values and when PropB is changed, the OnRep checks if its local PlayerState has the same PropA as the currently active player. So I can’t just send PropA again. I’m sure there’s a more involved way to solve my problem, I was just trying to understand why the current approach was not working and why I needed such a long delay.
Or you can call ForceNetUpdate to bypass the frequency and update asap.
But even then, that won’t guarantee anything.
If that’s the only issue, you can use OnRep on both PropA and PropB, check each other property, and funnel them into the same handler.
But if you need to update those two properties with every game “turn”, then on the next turn it’ll have the previous value instead of being empty, so that won’t work. Unless you also find a way to clear the values on client before next turn, then you can repeat the same thing.
Probably a better option : disable RepNotify and variable replication, and send both variables via reliable RPC. Update the values on client then run your handler.