Search Unity

UNetStaticUpdate called as part of Update() cycle?

Discussion in 'UNet' started by benmultiplayerguys, Oct 8, 2018.

  1. benmultiplayerguys

    benmultiplayerguys

    Joined:
    Oct 3, 2018
    Posts:
    9
    I've been benchmarking some UNet functionality and it seems that UNetStaticUpdate (and therefore, all my networking callbacks) gets executed once per frame. This is not ideal when running a server, because I want to have a low frame rate (via Application.targetFrameRate) to avoid wasting time on fast rendering, but a high network update rate, to ensure message queues are drained rapidly and latency is low.

    I'd reimplement UNetStaticUpdate myself and call it in FixedUpdate, but unfortunately it delegates to internal methods so it's not too practical.

    Can anyone else confirm that UNetStaticUpdate is called as part of the Update() cycle, and maybe suggest any workarounds to decouple networking from the rendering rate?
     
  2. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    It's called in each LateUpdate by the Unity engine.
    You could fork HLAPI from bitbucket and modify it to use UNetStaticUpdate in FixedUpdate or any other interval that you want to use instead.

    Note that this is not the biggest bottleneck. UNET's LLAPI seems to call send/recv in the main thread in Update all the time. We do that in a separate thread in Mirror, which doubles the frame rate. Or to be more precise, it just doesn't cut it in half.
     
  3. benmultiplayerguys

    benmultiplayerguys

    Joined:
    Oct 3, 2018
    Posts:
    9
    I've tried using reflection to call UNetStaticUpdate in FixedUpdate but it didn't seem to have any effect - perhaps because the LLAPI is not updating outside of those times and therefore there's nothing for the HLAPI to send or receive.

    I would be interested in doing sends and recvs in a different thread but TCP and thread-per-connection is a deal-breaker, so Mirror is not a simple drop-in solution for me.