Delay destruction and garbage collection of the networked player prefab when disconnecting

I need to find a way to delay the destruction of a players networked prefab when they disconnect. The problem is that if a player disconnects during a race (we are a racing game) then the subsequent immediate garbage collection of the networked player prefab causes stutter on all the other players still in the room - ruining the race.

So I need them to disconnect and then control and delay this garbage collection for the networked player prefabs until the end of the race when it can be done safely without impacting other players.

How do I go about doing this?

Comments

  • Got this reply from Exit games themselves and it answers enough of what I need to know ...

    there are many ways to go about this.

    -- you can separate the network prefab instance from the actual content of your game controlled with that instance, so the car model is a prefab instance on its own and the player network prefab instance controlling that car has a reference to the car instance. You then have a greater control over what gets destroyed automatically when a network player is disconnected. This is a very flexible approach indeed which doesn't need complex network handling and hacks.

    -- you can tell photon that you will be handling the destroying of objects by setting autoCleanUpPlayerObjects to false. https://doc-api.photonengine.com/en/pun/v1/class_photon_network.html#a6c6fb3cd57d7e2a13d1fc354db0c1fd7 then you are responsible for handling network instances destruction.

    -- you can set a player timeout value when disconnection is unwanted, which means player is "inactive" during the time and will remain until the time expires, in which caes, he will be out of the room as normal. This is probably what you want if you want to deal with unwanted disconnecion while you try to reconnect. https://doc-api.photonengine.com/en/pun/v2/class_photon_1_1_realtime_1_1_room_options.html#a209447cfcc1477298f53bd59d7771e88
Sign In or Register to comment.