asadm / playroom-unity

9 stars 1 forks source link

OnQuit doesn't fire on-time, when using reconnectGracePeriod #76

Open SaadBazaz opened 1 month ago

SaadBazaz commented 1 month ago

What happened?

After setting reconnectGracePeriod, onQuit doesn't fire on time (it fires randomly, or after the set time (e.g. if you set reconnectGracePeriod=4000, it will fire after 4 seconds).

Here's a video of it happening in the JavaScript SDK, in a project created by create-multiplayer-game:

https://github.com/asadm/playroom-unity/assets/51885228/72b8ef12-cde5-4cc4-b519-f51b98b9bf76

This is particularly problematic for developers building with the Unity SDK, as they use onPlayerJoin and onQuit as a way to manage players list in their game.

Suggestion

Add a function called onDisconnect which immediately fires upon disconnect, no matter what. We can then advise developers to use that, instead of onQuit.

onDisconnect -> When player disconnects (immediate) from the room onQuit -> When the player's state is cleared from the game (it may be delayed, due to reconnectGracePeriod or other reasons

Version

0.0.23

What is your environment?

Unknown

Link to original discussion

https://discord.com/channels/997752993598419044/1128151935669764096/1242461700406382695

Relevant log output

No response

asadm commented 1 month ago

Hmmm this is working as intended actually. onQuit fires late if grace period is set. So that game does not have to deal with someone quickly reconnecting, they will continue to work as-is with their state data intact.

SaadBazaz commented 1 month ago

Hmmm this is working as intended actually. onQuit fires late if grace period is set. So that game does not have to deal with someone quickly reconnecting, they will continue to work as-is with their state data intact.

Yes, that is good behavior. However, I recommend adding another callback called onDisconnect which immediately fires on Disconnect, no matter what.

Reason: The attached video shows some non-deterministic behavior. There is a brief period in which onPlayerJoin has been called, but onQuit hasn’t, which results in a possible double-avatar problem. By having onDisconnect, or some workaround, we should be able to prevent this double-avatar problem.

SaadBazaz commented 3 days ago

@asadm Were we able to look into this?