how to handle objects in background

I am playing a network game as one of multiple users. I press home button(Android phone) and then my game gets in background. My network object is still seen on other's phone, but it's not moving.
I'd like to change the status of my object, such as making it invisible or getting out of the game room.
So I tried to use PunRPC, but it seems not working while my game is on Pause(in background).

Is there any way to handle the network object which is on pause?

Comments

  • Sadly, I don't think I can figure out this issue by myself.

    would any technicians with Photon be kind to answer this question?
  • Hi @mhhk88,

    when pressing the home button and the game goes in background, Unity calls an OnApplicationPause(bool pause) or OnApplicationFocus(bool focus) function. You can implement one or both of them and try to send a certain message, that disables your object in a certain way. However I'm not sure, if you can send a message in background at all, you would have to try if it works.
  • mhhk88
    mhhk88
    edited July 2018
    I already tried it using both method (OnApplicationPause & OnApplicationFocus). But it didn't work for network objects.
    This is my codes.
    ....
    void OnApplicationPause(bool pauseStat) {
        if (pauseStat) {
            photonView.RPC("ProcessPause", PhotonTargets.All, photonView.ownerId, true);
        } else {
            photonView.RPC("ProcessPause", PhotonTargets.All, photonView.ownerId, false);
        }
    }
    
    [PunRPC]
    void ProcessPause(int playerId, bool pauseStat) {
        GameObject[] ftrs = GameObject.FindGameObjectsWithTag("FTR");
        for(int i=0; i<ftrs.Length; i++) {
            if (ftrs[i].GetComponent<PhotonView>().ownerId == playerId) {
                ftrs[i].GetComponent<TankDamage>().isOutOfGame = pauseStat;
                break;
            }
        }
    }
    ....

    Any suggestions?
  • You can try to force sending outgoing messages when the game goes into pause mode. To do so, you can add PhotonNetwork.SendOutgoingCommands(); after using the RPC function. Again, I'm not sure, if this is working.
  • It works !!!
    You just got me out of a long and dark tunnel. Thank you so much !!!