com.unity.netcode.gameobjects icon indicating copy to clipboard operation
com.unity.netcode.gameobjects copied to clipboard

Fix: Rpc transmitting which always consumed 5 frames over

Open mrsions opened this issue 1 year ago • 1 comments

The update cycle of Unity Transport and Network Manager was misaligned, so I read the data late and fixed the late transmission.

The client sends a ping packet to the Rpc, and then measures the time the server receives the ping packet.

When the server and the client operate at 1fps, it always takes 5 seconds. This is 5 frames.

Up to three frames, I understand logically, but I didn't understand that it was always five frames.

This was a structural defect in Unity Transport and resolved.

Current Update Cycle

  • Currently, it takes at least 5 frames to receive a PingPong packet after sending it to the Rpc.
  1. EarlyUpdate
    • NetworkManager.NetworkUpdate(EarlyUpdate)
      • NetworkTransport.PollEvent() : The data read in the previous frame is processed.
  2. Update
    • UnityTransport.Update()
      • NetworkDriver.ScheduleUpdate() : Since the work was done in EarlyUpdate, the data read here will be done in the next frame. The data that was supposed to be transferred in the previous frame will now begin to be transferred.
  3. PostLateUpdate
    • NetworkManager.NetworkUpdate(PostLateUpdate)
      • MessageManager.ProcessSendQueue() : The Send Queue saved here is flushed to the Update in the next frame later

Fixed Update Cycle

  • Now, after sending the PingPong packet, it is received within 1 ~ 3 frames.
  1. Initialize
    • UnityTransport.OnNetworkUpdate(Initailzie) [NEW]
      • NetworkDriver.ScheduleUpdate() : Reads the data to be processed by EarlyUpdate.
  2. EarlyUpdate
    • NetworkManager.NetworkUpdate(EarlyUpdate)
      • NetworkTransport.PollEvent()
  3. PostLateUpdate
    • NetworkManager.NetworkUpdate(PostLateUpdate)
      • MessageManager.ProcessSendQueue()
    • UnityTransport.OnNetworkUpdate(PostLateUpdate) [NEW]
      • NetworkDriver.ScheduleFlushSend() : Send what Network Manager has processed immediately.

Changelog

  • Added: UnityTransport works as a NetworkUpdate lifecycle update.
  • Fixed: Does not read UnityTransport data 1 frame later.
  • Fixed: The data in UnityTransport is not transmitted 1 frame later.

Testing and Documentation

  • No tests have been added.
  • No documentation changes or additions were necessary.
  • Includes documentation for previously-undocumented public API entry points.
  • Includes edits to existing public API documentation.

mrsions avatar Apr 30 '24 17:04 mrsions

CLA assistant check
All committers have signed the CLA.

unity-cla-assistant avatar Apr 30 '24 17:04 unity-cla-assistant