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.
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.
0
Comments
-
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??
0 - 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.
-
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.0 -
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 checkotherPlayer.IsInactive
, the first time it'strue
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 FYI0 -
Hi @JohnTube
I tried your solution but on both OnPlayerLeftCalls callsIsInactive
is true. The only thing changes during the second call isPhotonNetwork.PlayerList.Length
. The first time it is 2 and on second call it's 1.
How to handle actual disconnection in such cases!
0 -
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!0