Rejoin room bug PUN2

Options
So i have the following issue: i create a room(player ttl=60 secs) , i join one player(A used to keep the room alive when player B disconnects) and instantiate it's character, then another player(B the one who disconnects) and instantiate its character, when player B disconnects due to internet issues(disable adapter) i call ReconnectAndRejoin which successfully rejoins the room(so far so good each player have it s own character), now disconnect player B again and rejoins at this moment player B will have two characters, each time i disconnect player B and reconnect it the number of B characters duplicates (1,2,4,8 ...).

The behaviour i expect is when disconnected and reconnected player B should have one character no matter how manny times i disconnect and reconnect to the same room.
This problem can be reproduced with the demo slot racer too with a little change to OnJoinedInstantiate.cs after the prefab instantiation from the provided list make shure to null the list so it won't call instantiate every time you rejoin the room, now if you repeat the steps i sayd after each disconnect and reconnect you will have 1,2,4 ... controllers
Does anyone have any idea how to fix this??

Comments

  • Hi @ddalacu,

    this isn't a bug. The thing is, that the player, who disconnects from the room, becomes inactive because you have set PlayerTtl. So his buffered messages (i.e. Instantiation calls) are not removed from the server's cache. This will only happen, if the player either leaves the room without becoming inactive or after the timer for PlayerTtl expires. Furthermore his objects are not removed, too.

    If the client now reconnect and rejoins the room, he will instantiate his object again (remember the cached Instantiation call). Next to it you maybe have another PhotonNetwork.Instantiate call, which gets processed, for example in the OnJoinedRoom callback. Afterwards the player has already two objects. This obviously stacks up until the client is entirely removed from the server (either by leaving the room without becoming inactive or after the PlayerTtl timer expires).

    To work around this, you should surround the PhotonNetwork.Instantiate call with a condition, so that it isn't called, when the client has already instantiated his object.
  • ddalacu
    ddalacu
    edited October 2018
    Options

    Hi @ddalacu,

    this isn't a bug. The thing is, that the player, who disconnects from the room, becomes inactive because you have set PlayerTtl. So his buffered messages (i.e. Instantiation calls) are not removed from the server's cache. This will only happen, if the player either leaves the room without becoming inactive or after the timer for PlayerTtl expires. Furthermore his objects are not removed, too.

    If the client now reconnect and rejoins the room, he will instantiate his object again (remember the cached Instantiation call). Next to it you maybe have another PhotonNetwork.Instantiate call, which gets processed, for example in the OnJoinedRoom callback. Afterwards the player has already two objects. This obviously stacks up until the client is entirely removed from the server (either by leaving the room without becoming inactive or after the PlayerTtl timer expires).

    To work around this, you should surround the PhotonNetwork.Instantiate call with a condition, so that it isn't called, when the client has already instantiated his object.

    The problem is that photon sends the cached event multiple times, i made a video about it please take a look, i could probably fix this but it does seems to be from photon.
    https://youtu.be/dOE9VvM-Npk

  • Thank you for reporting this issue. I have taken a look at the video and created a repro case myself. I have already nailed the reason why this happens down, but haven't found a solution yet. I will keep you updated.
  • Hi @ddalacu,

    the issue has been fixed and will be part of the next update. Right now you would have to apply this fix on your own.

    Therefore I'm asking you to navigate to the PhotonNetwork class, open it and look for the private static GameObject NetworkInstantiate(Pun.InstantiateParameters parameters, bool sceneObject = false) function. Replace it with the following code: private static GameObject NetworkInstantiate(Pun.InstantiateParameters parameters, bool sceneObject = false, bool instantiateEvent = false). The only difference is the new optional parameter at the end of the parameter list.

    Inside this function you will find bool localInstantiate = LocalPlayer.Equals(parameters.creator);. Replace this code with the following one: bool localInstantiate = !instantiateEvent && LocalPlayer.Equals(parameters.creator);. The difference here is, that we make use of the new optional parameter.

    Lastly look for the private static GameObject NetworkInstantiate(Hashtable networkEvent, Player creator) function. At the end of this function you will find return NetworkInstantiate(netParams, false);. Replace if with the following code: return NetworkInstantiate(netParams, false, true);.

    Again, thanks for reporting this issue. Please let me know, if there is something still not working as expected.
  • ddalacu
    Options
    Seems to work :), thanks for the quick fix!
  • NetMaster
    Options
    Hello,

    I use PUN2 and have exactly the same problem with latest PUN2. When a client leave the room and rejoin back, then on the client I get after each login more and mor clones... and one of them is the master.
    And yes, I use PhotonNetwork.Instantiate for creating the prefabs. Can someone help?
  • NetMaster
    NetMaster
    edited May 2020
    Options
    I solved it by self.
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @NetMaster,

    Thank you for choosing Photon and for the update.
    Very good job on solving it all by yourself!

    Could you share your solution so others can benefit from it.

    Again, well done for doing it on your own.
  • NetMaster
    NetMaster
    edited May 2020
    Options
    JohnTube wrote: »
    Hi @NetMaster,

    Thank you for choosing Photon and for the update.
    Very good job on solving it all by yourself!

    Could you share your solution so others can benefit from it.

    Again, well done for doing it on your own.

    Hello,

    I had manually to clear the cached Room after leaving the room, this has solved the issue. I dont know why the room options CleanupCacheOnLeave = true didn't work. Is this still a bug?
  • SakshiC
    Options
    Hello,[url][/url]
    I am using Pun2 for my Project everything is working fine except reconnect and rejoin issue when player got disconnected because of the network issue.

    I am having the same issue mentioned above like:

    when player B disconnects due to internet issues(disable adapter) i call ReconnectAndRejoin which successfully rejoins the room(so far so good each player have it s own character), now disconnect player B again and rejoins at this moment player B will have two characters, each time i disconnect player B and reconnect it the number of B characters duplicates (1,2,4,8 ...).

    and this room options CleanupCacheOnLeave = true didn't work for me.

    and i am unable to solve this issue and sometimes i found another issue which i have attached in screenshot.
    Please Help me to resolve this ReconnectAndRejoin issue.


    Thanks