- Home /
Send a Pause RPC on OnApplicationPause
I have a real-time multiplayer game for iOS. I'm trying to pause the game for all players when any player multitasks out of the app (OnApplicationPause).
I have a RequestPauseGame method that sends an RPC to the server, which sends one to all the players, which pauses their games. This all works.
protected void OnApplicationPause( bool paused )
{
//pause game when applicaiton is paused (enters background)
if (isGameRunning && paused)
{
RequestPauseGame();
}
}
My problem is, after OnApplicationPause fires, the game thread is slept, so my RPC method doesn't actually send. Then when I return to the app, the RPC goes through and the game is paused network-wide.
The only solution I can think of is to constantly send RPCs to the server from each client, so the server knows they're still there. Then if I don't hear back from a client after a specific timeout, I know they're paused. If they stay paused for too long, my server automatically assumes they disconnected.
I want to avoid sending tons of RPCs though, as I'm trying to decrease network usage as is. Anyone have alternative suggestions on how to get around the thread sleeping of OnApplicationPause?
Answer by KelNishi · Oct 24, 2013 at 09:22 AM
I haven't figured out how to do this with the built-in Unity networking, but with Photon, you can add the following line after your RPC call:
PhotonNetwork.networkingPeer.SendOutgoingCommands();
Interesting... I'm using uLink, which has roughly the same API as Unity Networking, so hopefully there's an equivalent of that. I'll post here if I find something. Thanks!
Couldn't find an equivalent with uLink. I assumed RPCs were sent immediately upon calling them... I'm having issues even rendering 1 more frame in order to cover up my puzzle game so users can't cheat. This HAS to be possible! No one with this problem gets answers on all the forums I've checked :(
Your answer
Follow this Question
Related Questions
Unity 5.0.2 iOS IL2CPP Networking RPC Issues 1 Answer
iOS IL2CPP Networking Issues Unity 5.0.x 3 Answers
Keep network connection from interrupting on iOS multitasking switch 1 Answer
iOS / Android OnApplicationPause: incoming calls vs home button 1 Answer
Is there a way to pause the game before it goes to the background? 0 Answers