Search Unity

Resolved How to optimize transform sync?

Discussion in 'Multiplayer Dev Blitz Day 2022' started by Aduci, Oct 27, 2022.

  1. Aduci

    Aduci

    Joined:
    Mar 11, 2016
    Posts:
    2
    Hi Unity :)
    I would like to ask you about the optimization of the band-width for an RTS game, where each players have around 30-40 units / soldiers each, and I would like to sync their transforms.
    Currently using NetworkTransforms is extremely band-width heavy, and there are no optimization options. (~32 bytes / tick / unit, so lets say we have 30 ticks / second, and 150 units, it is ~150Kb / sec only for the NetworkTransforms.
    Do you have any suggestions to the topic?
    It would be extremely useful to have some kind of compression or the option to use different variables (smaller than floats) for the position / rotation sync.
     
  2. lp_lafb

    lp_lafb

    Unity Technologies

    Joined:
    Sep 21, 2021
    Posts:
    4
    Hi Aduci,

    The NetworkTransform component allows you to configure which axes are synchronized. For example, if your RTS game has every unit at the same Y position, you can toggle off synchronization of the Y position axis, as well as the X and Z rotation axes and the scale. This will reduce your bandwidth usage per tick per unit. You can also increase the thresholds to reduce the frequency of updates to the NetworkTransform and let the interpolation do the rest of the work, but it will reduce the accuracy and responsiveness of the replicated transform. You could also decide to reduce the NetworkManager's tick rate. The same drawbacks appear here as with the threshold increases though, so you would have to do some testing to choose a value that fits your project.

    NetworkTransform sadly does not offer compression features, as it fell out of scope for small-scale coop. You can however create a custom implementation that uses some optimization techniques. For example, you can use quantization to encode your values into bits/bytes and decode them when receiving the updates. For example, if you know that position values will always be between 0 and 1000 and do not care about accuracy beyond 0.1, you can multiply each value by 10 to get an integer between 0 and 10000, then encode this in bits directly. You would then only need 14 bits per axis instead of a full float.