How can I remove a player's prefab on Disconnect() ?

I using webhooks so I need EmptyRoomTTL = 0 and PlayerTTL = -1.
I using Disconnect instead LeaveRoom.

After player disconnect his prefab is still in room. How can I destroy him for others and for him ? On rejoining there is some photonView ID conflicts.

I know about PhotonNetwork.Destroy, tried to use it but it does not works.

Answers

  • Have you set PhtonNetwoel.autocleanup option to true ? That should cleanup the objects.
  • @Tinasious , is it default value "false"?
  • You could go with the Photon OnPhotonPlayerDisconnected(PhotonPlayer player) callback.
    private void OnPhotonPlayerDisconnected(PhotonPlayer otherPlayer) 
    {
             if (PhotonNetwork.player == otherPlayer) 
             {
                     PhotonNetwork.Destroy(myPlayerObject);
             }
    }
    The reason for the if statement is because that callback is called for all players currently in the same room so we make sure to only destroy our player when we disconnect.
Sign In or Register to comment.