diff --git a/Assets/Mirror/Components/NetworkTransform/NetworkTransformBase.cs b/Assets/Mirror/Components/NetworkTransform/NetworkTransformBase.cs index 8b64f8c35..d225134d0 100644 --- a/Assets/Mirror/Components/NetworkTransform/NetworkTransformBase.cs +++ b/Assets/Mirror/Components/NetworkTransform/NetworkTransformBase.cs @@ -313,13 +313,22 @@ void RpcReset() // common Teleport code for client->server and server->client protected virtual void OnTeleport(Vector3 destination) { - // reset any in-progress interpolation & buffers - Reset(); - // set the new position. // interpolation will automatically continue. target.position = destination; + // reset interpolation to immediately jump to the new position. + // do not call Reset() here, this would cause delta compression to + // get out of sync for NetworkTransformReliable because NTReliable's + // 'override Reset()' resets lastDe/SerializedPosition: + // https://github.com/MirrorNetworking/Mirror/issues/3588 + // because client's next OnSerialize() will delta compress, + // but server's last delta will have been reset, causing offsets. + // + // instead, simply clear snapshots. + serverSnapshots.Clear(); + clientSnapshots.Clear(); + // TODO // what if we still receive a snapshot from before the interpolation? // it could easily happen over unreliable. @@ -329,14 +338,23 @@ protected virtual void OnTeleport(Vector3 destination) // common Teleport code for client->server and server->client protected virtual void OnTeleport(Vector3 destination, Quaternion rotation) { - // reset any in-progress interpolation & buffers - Reset(); - // set the new position. // interpolation will automatically continue. target.position = destination; target.rotation = rotation; + // reset interpolation to immediately jump to the new position. + // do not call Reset() here, this would cause delta compression to + // get out of sync for NetworkTransformReliable because NTReliable's + // 'override Reset()' resets lastDe/SerializedPosition: + // https://github.com/MirrorNetworking/Mirror/issues/3588 + // because client's next OnSerialize() will delta compress, + // but server's last delta will have been reset, causing offsets. + // + // instead, simply clear snapshots. + serverSnapshots.Clear(); + clientSnapshots.Clear(); + // TODO // what if we still receive a snapshot from before the interpolation? // it could easily happen over unreliable. diff --git a/Assets/Mirror/Components/NetworkTransform/NetworkTransformReliable.cs b/Assets/Mirror/Components/NetworkTransform/NetworkTransformReliable.cs index f3d4afde7..d88cf8683 100644 --- a/Assets/Mirror/Components/NetworkTransform/NetworkTransformReliable.cs +++ b/Assets/Mirror/Components/NetworkTransform/NetworkTransformReliable.cs @@ -405,6 +405,9 @@ static void RewriteHistory( ); } + // reset state for next session. + // do not ever call this during a session (i.e. after teleport). + // calling this will break delta compression. public override void Reset() { base.Reset();