From 016b611b2b5f362bd4259d398cad0d796c61779f Mon Sep 17 00:00:00 2001 From: mischa <16416509+miwarnec@users.noreply.github.com> Date: Mon, 2 Sep 2024 22:03:38 +0200 Subject: [PATCH] breaking: NetworkTransform sendIntervalMultiplier replaced by syncInterval math (#3895) * repro * force sendIntervalMultiplier based on syncInterval! * Revert "repro" This reverts commit e51c996fa61d5fa4b3720447f0abca2f628990f3. * cleanup * fix * hide * property * rmv --------- Co-authored-by: mischa --- .../NetworkTransform/NetworkTransformBase.cs | 44 ++++++++++++++----- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/Assets/Mirror/Components/NetworkTransform/NetworkTransformBase.cs b/Assets/Mirror/Components/NetworkTransform/NetworkTransformBase.cs index ab00ba22f..2ec138346 100644 --- a/Assets/Mirror/Components/NetworkTransform/NetworkTransformBase.cs +++ b/Assets/Mirror/Components/NetworkTransform/NetworkTransformBase.cs @@ -67,10 +67,39 @@ public abstract class NetworkTransformBase : NetworkBehaviour [Tooltip("Local by default. World may be better when changing hierarchy, or non-NetworkTransforms root position/rotation/scale values.")] public CoordinateSpace coordinateSpace = CoordinateSpace.Local; - [Header("Send Interval Multiplier")] - [Tooltip("Check/Sync every multiple of Network Manager send interval (= 1 / NM Send Rate), instead of every send interval.\n(30 NM send rate, and 3 interval, is a send every 0.1 seconds)\nA larger interval means less network sends, which has a variety of upsides. The drawbacks are delays and lower accuracy, you should find a nice balance between not sending too much, but the results looking good for your particular scenario.")] - [Range(1, 120)] - public uint sendIntervalMultiplier = 1; + // TODO sendIntervalMultiplier was replaced by syncInterval for consistency with other NetworkBehaviours. + // for now, we simply calculate the multiplier based on syncInterval. + // in a future, we can remove this completely and replace with syncInterval math everywhere. + // the multiplier math isn't that simple, so for now this is a good solution! + public uint sendIntervalMultiplier + { + get + { + if (syncInterval > 0) + { + // if syncInterval is > 0, calculate how many multiples of NetworkManager.sendRate it is + // + // for example: + // NetworkServer.sendInterval is 1/60 = 0.16 + // NetworkTransform.syncInterval is 0.5 (500ms). + // 0.5 / 0.16 = 3.125 + // in other words: 3.125 x sendInterval + // + // note that NetworkServer.sendInterval is usually set on start. + // to make this work in Edit mode, make sure that NetworkManager + // OnValidate sets NetworkServer.sendInterval immediately. + float multiples = syncInterval / NetworkServer.sendInterval; + + // syncInterval is always supposed to sync at a minimum of 1 x sendInterval. + // that's what we do for every other NetworkBehaviour since + // we only sync in Broadcast() which is called @ sendInterval. + return multiples > 1 ? (uint)Mathf.RoundToInt(multiples) : 1; + } + + // if syncInterval is 0, use NetworkManager.sendRate (x1) + return 1; + } + } [Header("Timeline Offset")] [Tooltip("Add a small timeline offset to account for decoupled arrival of NetworkTime and NetworkTransform snapshots.\nfixes: https://github.com/MirrorNetworking/Mirror/issues/3427")] @@ -116,13 +145,6 @@ protected virtual void Configure() // set target to self if none yet if (target == null) target = transform; - // time snapshot interpolation happens globally. - // value (transform) happens in here. - // both always need to be on the same send interval. - // force the setting to '0' in OnValidate to make it obvious that we - // actually use NetworkServer.sendInterval. - syncInterval = 0; - // Unity doesn't support setting world scale. // OnValidate force disables syncScale in world mode. if (coordinateSpace == CoordinateSpace.World) syncScale = false;