PhotonNetwork.ReconnectAndRejoin(); Create new PhotonView and destroying older Photon View

Hello,
When user disconnects by unexpected network error we are using PhotonNetwork.ReconnectAndRejoin(); in same scene..

we are able to rejoin to same room, But the problem is photon is destroying existing players photonviews. and instantiating new views..

How to reuse same photonviews which are already avialble in same scene and room..

Game state is preserved in Players PhotonViews like player health and weapons etc.

How to prevent auto instantiation happening from Photon on rejoin..?

Why it is destorying existing Views as these are already owened by Player and avaible in same room.

Answers

  • Hi @Balutm,

    when the client gets disconnected, is he becoming incative (requires you to set PlayerTtl in the RoomOptions) or is he fully disconnected from the room? When the client becomes inactive and rejoins the room before the server timeouts him (PlayerTtl), he can reuse his objects by default. If he gets disconnected from the room and does not become inactive, his objects will be removed as well.

    If his objects don't get removed (the client successfully reconnects without being fully disconnected from the room), you don't have instantiate new objects for him.
  • Hi @Christian_Simon ,
    thank you for reply,
    In our case we have PlayerTtl is 5 min. and he is disconnected but still in inactive,

    I was wondering why Inactive mode is treating as new connection and creating new objects as well.

    after disconnecting also I can see player Objects exist in other clients...

    How to reuse existing objects
  • Hi @jeanfabre ,
    Can also please check discussion..?
  • Hi,

    I think you should refactor and save health and other player settings in Player Properties, this is best and most reliable mechanism that is supported by Pun for this scenario. PhotonViews are disposable by default and should always be handled by PUN automatically. if you choose to handle this manually, you are opening a can of worm, and you need to have a great level of expertise to provide a bullet proof mechanism for this. We simply do not recommend it.

    So let PhotonViews without states, and instead rely on Player Custom Properties, they will survive re connection while player is inactive in a room.

    Bye,

    Jean
  • Balutm
    Balutm
    edited May 2018
    Hello @Jeanfabre,

    I can understand whatever you suggested, but actually it is also the problem of re Instantiating Objects which are already in Scene..

    Instead we can read values from Players Custom Properties and assign to existing PhotonView objects.

    In our case the Object of Player Is huge with guns and character meshes and etc..

    Destroying and re Instantiating will may lead to performance issue.

    How can I control photon's automating process of PhotonViews..?


    I can Instantiate my own views.

    Thank You.

  • Hi @Balutm,
    When the client becomes inactive and rejoins the room before the server timeouts him (PlayerTtl), he can reuse his objects by default. If he gets disconnected from the room and does not become inactive, his objects will be removed as well.
    .

    This is similar to what we are looking.. as you mentioned...


    he can reuse his objects by default. ..?
  • Maybe the following code snippet is good way to start solving this situation:
    public void OnJoinedRoom()
    {
        if (!wasConnected)
        {
            PhotonNetwork.Instantiate(...);
            wasConnected = true;
        }
    }
    In this example I'm using the OnJoinedRoom callback which gets called every time the client joins (or rejoins) a room. If the client hasn't been in a room before (wasConnected is false in this case), he instantiates his object and sets the wasConnected value to true. If he now disconnects and rejoins the room, the code inside the condition is not processed and the client won't instantiate another object. This is a simple solution that only works properly for rejoining. There are other cases you have to think about, for example if a client joins another room. In this case you would have to reset the wasConnected value to false. Another case is when the client times out (PlayerTtl). In this case you would have to add something like a background timer, which takes care of this scenario.
  • Hi @Christian_Simon ,

    I already tried this, next time if joins back we are checking like you mentioned above and we are not calling PhotonNetwork.Instantiate(...); for inactive players in OnJoinedRoom()

    But still automatically existing Photon view objects are re instantiating and resetting positions, rotations values etc.



  • @jeanfabre , please let us know if you have any solution to stop automatic PhotonViews creations at least for inactive players for rejoin.

    Thank You.