SetMasterClient not working on OnApplicationPause

When I click on phone home button all debug come but SetMasterClient not work. i.e RPC does not call for other players.
public void OnApplicationPause(bool pause)
{
      if (PhotonNetwork.isMasterClient && pause && PhotonNetwork.playerList.Length > 1)
      {
           Debug.Log("OnApplicationPause Master Switch Start : " + pause);
           photonView.RPC("SyncRoom", PhotonTargets.All, JsonUtility.ToJson(managerInfo));
           PhotonNetwork.SetMasterClient(PhotonNetwork.otherPlayers[0]);
           Debug.Log("OnApplicationPause Master Switch End : " + pause);
      }
}
MaserClient Switches when I come back to game screen back...
please guide me on how can I achieve SetMasterClient onApplicationPause....or any other way?

Answers

  • Can You test in OnFocusApplication, if have not the focus, then you have pressed the home button
  • JohnTube
    JohnTube ✭✭✭✭✭
    Hi @AbhiwanPawan,

    Thank you for choosing Photon!

    You need to send the messages right away using PhotonNetwork.SendOutgoingCommands();, like this:
    public void OnApplicationPause(bool pause)
    {
          if (PhotonNetwork.isMasterClient && pause && PhotonNetwork.playerList.Length > 1)
          {
               Debug.Log("OnApplicationPause Master Switch Start : " + pause);
               photonView.RPC("SyncRoom", PhotonTargets.All, JsonUtility.ToJson(managerInfo));
               PhotonNetwork.SetMasterClient(PhotonNetwork.otherPlayers[0]);
               PhotonNetwork.SendOutgoingCommands();
               Debug.Log("OnApplicationPause Master Switch End : " + pause);
          }
    }
    But you need to consider a few things:
    While this is on PUN2 docs pages "Send Right Away", the same thing applies to PUN Classic.