OnApplicationFocus to switch MasterClient

Options
Hello! We are trying to make a multiplayer game. We have bots in game and all the bots are controlled by master client. The problem is that the method is not called immediately when the master client closes the application / shuts down the device / goes to the main screen. I mean the method is called after sometime but in some weird order:
1. master client closes the application / shuts down the device / goes to the main screen
2.. master client returns to the application
3. hasFocus = false
5. setMaster
4. hasFocus = true

But we need it to work in another order:
1. master client closes the application / shuts down the device / goes to the main screen
3. hasFocus = false
5. setMaster
2. previous master client returns to the application
4. hasFocus = true
  1. void OnApplicationFocus( bool hasFocus )
  2. {
  3. if (PhotonNetwork.isMasterClient && !hasFocus) {
  4. if (PhotonNetwork.otherPlayers.Length > 0) {
  5. agent.enabled = false;
  6. PhotonNetwork.SetMasterClient (PhotonNetwork.otherPlayers [Random.Range (0, PhotonNetwork.otherPlayers.Length)]);
  7. }
  8. }
  9. }
The problem seems to occur only on Android devices. We didn’t test it on iOS devices yet. Does anyone know how to solve the problem or what should we do? Thanks in advance!

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    edited March 2017
    Options
    Hi @Carter,

    I think you need to use OnApplicationPause and not OnApplicationFocus.