Questions about ReconnectAndRejoin

Our app logic is

JoinRoom -> OnJoinedRoom->PhotonNetwork.Instantiate


Now we add the TTL logic using PlayerTTL and ReconnectAndRejoin, we set the PlayerTTL to 60000,we simulate the environment by shutting down the wifi and reopen it.The rejoin logic is as follows:

judge the network is connected -> call ReconnectAndRejoin->OnJoinedRoom->PhotonNetwork.Instantiate

Using the above logic, every time one new player is created ,and the cached player on photon server is also Instantiated locally.

So what is the correct way to use ReconnectAndRejoin?our purpose is that the cached player and local player should be one player after reconnectandrejoin.

Comments

  • harlanharlan
    edited August 21
    hello @JohnTube

    we did some investigations and now know that when using ReconnectAndRejoin, PhotonNetwork.Instantiate should not be used locally and the player data is restored from photon server.But now has other two questions,
    • i moved to other position after I was born in the room, after ReconnectAndRejoin, the position cannot be restored and I am in where I was born again, so how to restore my position?I saw a post said that it can use SetCustomProperties to save the positions, but I think it is a waste for network traffic.
    • How to know the IsInactive value changed when some other player disconnect from photon server.I already did some tests, and found that OnPlayerPropertiesUpdate is not called at all, and OnPlayerLeftRoom is called two times ,a little strange,, maybe it is called the first time when other player disconnect from server, and second time when the player TTL is overdue??
    Please help me if you have time, thanks.
  • Hi @harlan,

    I'm glad you found out that Instiantiate calls are cached events and the server sends those automatically to newly/late joiners or rejoiners.
    But now has another question, i moved to other position after I was born in the room, after ReconnectAndRejoin, the position cannot be restored and I am in where I was born again, does PUN support this?
    I don't think so. PhotonView synchronization events are not cached so you would need to find a solution for this yourself.
  • harlanharlan
    edited August 22
    Thanks @JohnTube

    Please see my second question above, thank you.
  • JohnTubeJohnTube mod
    edited November 6
    OnPlayerLeftRoom is called two times ,a little strange,, maybe it is called the first time when other player disconnect from server, and second time when the player TTL is overdue??
    You guessed right yes. OnPlayerLeftRoom(Player otherPlayer) can be called twice when PlayerTTL > 0. You can check otherPlayer.IsInactive, the first time it's true the second time it's not.

    EDIT: correct way to tell when an actor is removed from the room vs. became inactive is shown below here.
    @harlan FYI
  • harlanharlan
    edited August 24
    that's good ,thanks @JohnTube
  • SathyarajSathyaraj
    edited November 6
    Hi @JohnTube
    I tried your solution but on both OnPlayerLeftCalls calls IsInactive is true. The only thing changes during the second call is PhotonNetwork.PlayerList.Length. The first time it is 2 and on second call it's 1.
    How to handle actual disconnection in such cases!
  • Hi @Sathyaraj,

    You're right, I will rectify the other post.
    Until we have a better way to handle this, you could do this:
    void OnPlayerLeftRoom(Player otherPlayer)
    {
        bool leftForGood = !PhotonNetwork.CurrentRoom.Players.ContainsKey(otherPlayer.ActorNumber); 
    }
    Thank you for your understanding!
  • Hi @JohnTube,
    Yes. for now we are using the above suggested workaround. Thanks.
Sign In or Register to comment.