Let me provide a little bit of background on what I’m experiencing.
I’m testing a turn-based board game on different devices (a pc (client), a phone (client), and an iPad (host)) and it works correctly if the games are running without any stop (as long as they keep synchronizing). Each player has a timer for their turn, and some buttons to perform some actions. Here’s the key thing: Only one action is allowed per turn. When the player chooses an action, the timer stops, it performs the action, and the next player gets his turn.
Now, the problem comes when the host (iPad) opens another app and the game runs in the background, or better said, stalls until the app/game is back on screen. During this time, the timer of the current player’s turn stops, while it continues on the clients’ game (phone and PC, in this case). So, whenever the iPad comes back, timers will not be synchronized across devices, which might be a big problem.
Another issue is that, when the host is not running the game, a player can hit a button to perform an action, but nothing will happen since the [ServerRpc (RequireOwnership = false)] function
won’t be performed until the host comes back. This is fine; however, if the client keeps pressing the button multiple times (let’s say 10 times), when the host comes back, the [ServerRpc (RequireOwnership = false)] function
will run 10 times instantly, breaking the game since only one action is allowed per turn.
I hope this kind of explains the problem.
A possible solution that came to my mind would be to let the clients’ game freeze until the host comes back, so that the timer will keep synchronized and clients won’t be able to accumulate actions. A drawback will be that, if any client (for instance, the phone) stops running the game for a couple of minutes and then comes back, it will not be synchronized with the rest.
Any idea or suggestion is highly appreciated.