Replication race condition between Replicated GameState and RPC call on client.

SkunkHunt
Thu, 20 Mar 2025 19:43:27 +0000
Blueprint

Hello,

I’m working on a multiplayer card game. Think of my game flow as a state machine. And in each state, there will be data going from the server to the client, and then back again.

State machine:

1. Player1 does something

2. Player2 does something

3. Both players do something simultaneously.

4. Done. Reveal outcome.

5. Loop back to the beginning, and do it again.

I have replication and even RPCs working great. So far so good. But I ran into a race condition which is apparently normal, and I have some workaround ideas on how to do this, but I really want to know the proper way to do this so I’m not hacking nonsense together.

The race condition:

1. My server sets one or more variables in GameState

2. Server makes an RPC call to client to do some stuff.

3. Client receives the RPC call, but the client’s GameState has not yet updated with that change made in the previous step… So it’s out of sync.

I had the idea to use RPC calls to drive my state machine (the number steps shown above). But my client relys on the GmaeState being perfectly up to date from the server, which I apparently cannot rely on if I’m using RPCs. Because it seems GameState changes are batched and can be a little slow.

My ideas for a proper solution here. Let me know what you think or if you have a better more proper solution

Solution idea A.) Just drive my state machine from the server solely off RepNotfiy, instead of RPCs. But my key question & concern here is, will I still have out of sync issues? Let’s say my server needs to set 5 replicated variables in GameState before it can finally send the signal to the client via RepNotify. Will I still get out of sync issues of the LAST variable I set in my GameState is that signal used to tell the client to begin? How do I know that all 5 are updated on the client’s GameState? What if only 3 or 4 are updated and the last one didn’t make it into the batch update? This solution doesn’t seem to guarantee that it’s in sync.

Set Variable1 in GameState
Set Variable2 in GameState
Set Variable3 in GameState
Set Variable4 in GameState
Set Variable5 in GameState
Set StateReady Variable in GameState that tells the client to GO and process the state.

Solution idea B.) Keep driving my state machine via RPCs. Somehow do some sort of checksum on all the data saved in GameState. When the server sends a message to the client telling it to do stuff, send a parameter that represents the checksum, and the client will just sleep/delay until it’s local client GameState checksum matches the checksum in the param.

Edit: I just made another observation. I don’t want to put game logic functions in my GameState blueprint. So that means if I fully switch over to using RepNotify I’ll likely need to use a bunch of Event Dispatchers to send signals out of the GmaeState and into other classes (like my GameMode for example). This is a lot of over engineering feel :-\ where as the RPC approach felt very simple and clean but came with the out of sync issues.

9 posts - 5 participants