Get the master to locate a not responding user.

Hey, I'm trying to get the mysql database to know when the player is online or offline and have its last known positions..
Now, I tried to use onapplicationquit() method but it is very problematic and wont do any co routines or call methods at all.
So I try a different way, the master client checks if the player responds, or went off, if it doesn't it sends a coroutine which contains its last position and update the database that the user is offline at those values.

The problem is that I dont know how to check if the player is not responding for a long time or if it disconnected and save its last position before he did.


  • It would be much easier if you could implement this on the server (which is possible if you host yourself and use the Photon Server SDK).
    Saving the position for leaving players will only work if someone stays in the room. Else, it's not reliable someone saves your pos.
    I think everyone will have to save positions in intervals but this might become expensive.
  • benk0913
    edited July 2013
    Alright, a different option..

    Lets say I use
    void OnPhotonPlayerDisconnected(PhotonPlayer player)

    for knowing that the player has left the room, how do I access the photon instance that this player has instantiated (the character gameobject)
    and collect its username string (to send the database its state and location ) and its position values of XYZ?
  • As soon as OnPhotonPlayerDisconnected is fired, the PhotonNetwork.Instantiate-ed objects have already been destroyed.
    So you would have to manually spawn player objects and assign the photonviews manually (plus take care of deletion manually)
    OR add a OnDestroy to the playerobject and listen for the destroy there. This is easier.

    You could give this a try:

    [code2=csharp]void OnDestroy() {
    Debug.Log("Player left: "+photonView.owner+" at last position"+transform.position);
  • It works!
    You have just solved a problem I had issues with for like two months :).
    Great solution.
    Many thanks!