Remove Player ID when disconnect

Hello everyone, I'm new here, I have a little detail with PUN.

I'm making a game with rooms for 4 players and I use the ID of each player (numbers 1 to 4) in the code.

The problem is that when one of the players leaves the room and another one enters, instead of occupying the ID of the player who left, he generates a new one, for example:

In a room with 4 players, the player with ID 2 is disconnected, a new player joins and instead of obtaining ID = 2, he gets ID = 5.

I tried to set the ttl = 0 in the room options but it does not work, keep storing the ID of the player who is not there and what I need is always to use a maximum of 4 IDs.

What I can do?

Thanks for your attention


  • Hi @DarkPuppet,

    Thank you for choosing Photon!

    That is the expected behaviour of Player ID or Actor Number.
    It starts at 1 and is always incremental and values are never recycled or reused.
    It can "overflow" and go beyond MaxPlayers or PlayersCount.

    So if a user claims an actor number X then leaves the room for good, that actor number will never be reused.

    What you are looking for is a custom player index.
    PUN has a "UtilityScript\PhotonPlayer\PlayerNumbering.cs" try it out.
  • edited May 2019
    I can't found that code in my poton resources

    Sorry, I didn't say I'm using v1, because when I install v2 the code crash and don't recognizes UnityEngine library
  • JohnTubeJohnTube mod
    edited May 2019
    It should be "\Assets\Photon Unity Networking\UtilityScripts\PhotonPlayer\PlayerRoomIndexing.cs" in PUN1.
    because when I install v2 the code crash and don't recognizes UnityEngine library
    What Unity version did you try this on? we're not aware of issues for PUN2 unless you tried a 2019.2 beta or you have a problem in your project or there was some trouble during import.
Sign In or Register to comment.