asadm / playroom-unity

9 stars 1 forks source link

unreliable flag (WebRTC/P2P) doesn't work #64

Open SaadBazaz opened 2 months ago

SaadBazaz commented 2 months ago

What happened?

Is PlayroomKit.SetState non-reliable supposed to be called each frame? I'm experimenting calling it 20 times per second while the game runs at 60 pfs and the result is terrible. super lagged.

strings, json files it depends on the message. most are 50 bytes. inputs are smaller

the less the worse. sending it every frame (60 fps) works fine. I don't feel too much lag. but sending less times, feels laggy. the game does not freeze, only the objects that need some kind of synchronization feel laggy

After some experimentation

So here is what I found after many tests trying to reduce the number of messages across the network and make the game run more smoothly. My idea was to make the game run at 60 fps while sending messages at 20 fps.

Things I was doing wrong:

Things I was doing right:

After that changes, the result is: 👍 Local player runs smoothly. The host runs normally as always. Non-host players predict their position, validade it when receive the message from the host and if necessary recalculate the current position and apply an interpolation to the visual error. Lag is rarely noticeable. 👎 Other players still look laggy to the local player, in despite of the interpolation. The reason for that is that many messages are lost, so instead of receiving a new state every 50ms, sometimes the player have to wait 1 to 3 seconds to the next message. This results in a very noticeable effect. The player object get stuck for some seconds and only when a new state is received it moves again. The most weird part of all this is that if I raise the message sending rate, it starts to get better but still not ideal. In short, I have to send a lot of messages only to receive few of them. I wonder if there is something I can do to improve that or it is a Playroom limitation.

Expected behaviour

By default, states should be unreliable so they are sent fast. We should be experiencing this lag with unreliable. It would only happen if somehow it is using reliable connection, or there is something bottlenecking the code itself.

Version

I'm using v0.0.14

What is your environment?

Unknown

Link to original discussion

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

Relevant log output

Here's a link to test out the problem: https://devsoccerparty.playroom.gg click "custom" to create a new room, them with another instance of the game click "join" and enter the room code

SaadBazaz commented 2 months ago

@momintlh first do the obvious, check if unreliable=false is actually being called.

If things look good in code, ask the dev for a reproduction. It would be interesting to ask them to show their Network tab in the Chrome dev tools, as you might be able to see what kind of connection is being used. Then see their code usage; are they using the function correctly?

SaadBazaz commented 2 months ago

Another related issue could be #61 . It's possible that after our refactor of the setter functions in #62 , we may have resolved this problem (PS: We haven't released that fix yet). Note that the developer uses 0.0.14

momintlh commented 2 months ago

reliable=false is working fine

SaadBazaz commented 2 months ago

reliable=false is working fine

Is it actually faster than reliable=true? Is it really using webRTC for false?

Also, can you test on the game and see the chrome network tab output? It should show what reliable mode is being used.

SaadBazaz commented 1 month ago

@momintlh Jump into a Meet/Discord with the developer. Link is in the Issue.