diff --git a/Assets/Mirror/Components/NetworkTransform/NetworkTransformHybrid2022.cs b/Assets/Mirror/Components/NetworkTransform/NetworkTransformHybrid2022.cs index 69fb8cb4d..1fcfadbe9 100644 --- a/Assets/Mirror/Components/NetworkTransform/NetworkTransformHybrid2022.cs +++ b/Assets/Mirror/Components/NetworkTransform/NetworkTransformHybrid2022.cs @@ -261,13 +261,23 @@ void SerializeServerDelta(NetworkWriter writer, byte baselineTick, Vector3? posi if (syncScale) writer.WriteVector3(scale.Value); } - void DeserializeServerDelta(NetworkReader reader, out byte baselineTick, out Vector3? position, out Quaternion? rotation, out Vector3? scale) + bool DeserializeServerDelta(NetworkReader reader, out byte baselineTick, out Vector3? position, out Quaternion? rotation, out Vector3? scale) { - baselineTick = reader.ReadByte(); position = null; rotation = null; scale = null; + baselineTick = reader.ReadByte(); + + // unreliable messages may arrive out of order. + // ensure this is for the intended baseline. + // we don't want to put a delta onto an old baseline. + if (baselineTick != lastDeserializedBaselineTick) + { + Debug.Log($"[{name}] Client discarding unreliable delta for baseline #{baselineTick} because we already received #{lastDeserializedBaselineTick}"); + return false; + } + if (syncPosition) { position = reader.ReadVector3(); @@ -280,6 +290,8 @@ void DeserializeServerDelta(NetworkReader reader, out byte baselineTick, out Vec { scale = reader.ReadVector3(); } + + return true; } // cmd ///////////////////////////////////////////////////////////////// @@ -359,8 +371,10 @@ void RpcServerToClientDeltaSync(ArraySegment message) { using (NetworkReaderPooled reader = NetworkReaderPool.Get(message)) { - DeserializeServerDelta(reader, out byte baselineTick, out Vector3? position, out Quaternion? rotation, out Vector3? scale); - OnServerToClientDeltaSync(baselineTick, position, rotation, scale); + if (DeserializeServerDelta(reader, out byte baselineTick, out Vector3? position, out Quaternion? rotation, out Vector3? scale)) + { + OnServerToClientDeltaSync(baselineTick, position, rotation, scale); + } } } @@ -378,15 +392,6 @@ protected virtual void OnServerToClientDeltaSync(byte baselineTick, Vector3? pos // don't apply for local player with authority if (IsClientWithAuthority) return; - // unreliable messages may arrive out of order. - // ensure this is for the intended baseline. - // we don't want to put a delta onto an old baseline. - if (baselineTick != lastDeserializedBaselineTick) - { - Debug.Log($"[{name}] Client discarding unreliable delta for baseline #{baselineTick} because we already received #{lastDeserializedBaselineTick}"); - return; - } - Debug.Log($"[{name}] Client: received delta for baseline #{baselineTick}"); // on the client, we receive rpcs for all entities.