PUN 2 Destroying all PhotonView Objects While Internet Connection Is Lost

Greetings! I'm using PUN 2 (v2.27, lib 4.1.4.9).

Recently I ran into such a problem - a photon removes all Photon View objects when the Internet connection is lost. Studying various issues on the forums, I came to the idea of using
RoomOptions.CleanupCacheOnLeave = false;
, but this is not worked for me. After I tried to find a boolean
PhotonNetwork.autoCleanUpPlayerObjects
, unsuccessfully, perhaps this feature was removed.

The main task - in the absence of the Internet, the player should not be destroyed by disconnecting from the room.

Please, help me. Thx :D

Comments

  • Have you used syncscene?
  • Clevereen wrote: »
    Have you used syncscene?

    I apologize for taking a long time to answer, but no, we do not use this, the room exists as soon as the first client-master is authorized, after which the clients connect freely during the game.
  • I used automaticallySyncScene but objects still destroyed.

    @AlexSmithCore Are you calling anywhere of your code manually PhotonNetwork.Disconnect for game logic during connection lost? I'm thinking this might be cause this.
  • L3sc wrote: »
    I used automaticallySyncScene but objects still destroyed.

    @AlexSmithCore Are you calling anywhere of your code manually PhotonNetwork.Disconnect for game logic during connection lost? I'm thinking this might be cause this.

    Nope, Disconnect is called directly from PhotonHandler while connection lost. Of all the possible options, write your own custom initializer for objects on the network.

    I don't see any other options yet.
  • Other things, to avoid the scene object to be destroyed while there is a disconnection, avoid sync scene. I use to have this issue. When the master Client is disconnected all object are destroyed. What I use is to handle the "sync" scene with conditions.

    i.e => If both players have spawned their Avatars, then start the game. I used this because when the master client left the room, everything was destroyed.
  • @Clevereen
    Objects destroyed only disconnected side. Prefabs still alive other client.
    RoomOptions.CleanupCacheOnLeave = false;
    
    doing this but it doesn't work properly or we are missing a point.
  • L3sc wrote: »
    @Clevereen
    Objects destroyed only disconnected side. Prefabs still alive other client.
    RoomOptions.CleanupCacheOnLeave = false;
    
    doing this but it doesn't work properly or we are missing a point.

    I have exactly same problem. Did u find a solution? On disconnected user, all network objects are destroyed. I dont want this...
  • Hello @L3sc and @Gokhaan

    When you say the objects get destroyed, can you confirm this is only for the local player OR for the other player as well?
    even though you set
    RoomOptions.CleanupCacheOnLeave = false;
    

    sometimes your object seemed to be destroyed because when you are facing a disconnection.

    WHY?
    Because when you are disconnected you are "kicked" from the room. So you have to reconnect and rejoin the previous room.
    When you will do this, you will see that all your network object will be re-instantiated (this is apparently a normal behaviour of PUN2).

    Also, Make sure that when you create your room, the option is set like this
    PhotonNetwork.CreateRoom("Room" + randomNumb, new RoomOptions
                {
                    CleanupCacheOnLeave = false,
                    PlayerTtl = 60000, // 60 sec
                });
    

    to reconnect, try something like this with the PUN 2 callbacks
    public override void OnDisconnected(DisconnectCause cause)
        {
            PhotonNetwork.Reconnect();
        }
    
        public override void OnConnectedToMaster()
        {
            //ONCE YOU ARE CONNECTED TO THE MASTER SERVER TRY TO REJOIN THE ROOM
            PhotonNetwork.RejoinRoom(roomName);
        }
    

  • Clevereen wrote: »
    Hello @L3sc and @Gokhaan

    When you say the objects get destroyed, can you confirm this is only for the local player OR for the other player as well?
    even though you set
    RoomOptions.CleanupCacheOnLeave = false;
    

    sometimes your object seemed to be destroyed because when you are facing a disconnection.

    WHY?
    Because when you are disconnected you are "kicked" from the room. So you have to reconnect and rejoin the previous room.
    When you will do this, you will see that all your network object will be re-instantiated (this is apparently a normal behaviour of PUN2).

    Also, Make sure that when you create your room, the option is set like this
    PhotonNetwork.CreateRoom("Room" + randomNumb, new RoomOptions
                {
                    CleanupCacheOnLeave = false,
                    PlayerTtl = 60000, // 60 sec
                });
    

    to reconnect, try something like this with the PUN 2 callbacks
    public override void OnDisconnected(DisconnectCause cause)
        {
            PhotonNetwork.Reconnect();
        }
    
        public override void OnConnectedToMaster()
        {
            //ONCE YOU ARE CONNECTED TO THE MASTER SERVER TRY TO REJOIN THE ROOM
            PhotonNetwork.RejoinRoom(roomName);
        }
    

    Hi @Clevereen

    As I said above, objects destroyed only at disconnected player. Objects stay alive on the other side. What we want is objects stay alive on both side. If we want to destroy something we can destroy it later according to situation. Why I want this: There are many scripts attached to destroyed objects and they lost their execution order when they destroyed in 1 side...

    So basically no way to stop destroying objects on both side???

    Thanks for your answer
  • @Gokhaan Unfortunately there is no way to stop destroying. As mentionned, if you use Photonviews to instantiate and the player leaves, sometimes their GO are destroyed.

    You really need to store the values somewhere and when the player reconnect, reset everything the way it was before the disconnection.

    that's quite a lot of word, that's why I avoid as much to use PhotonNetwok.Instantiate