Skip to content

Commit

Permalink
fix: MirrorNetworking#3588 NetworkTransform OnTeleport doesn't call R…
Browse files Browse the repository at this point in the history
…eset() anymore, causing NetworkTransformReliable's delta compression to get out of sync before
  • Loading branch information
mischa committed Nov 1, 2023
1 parent a432b7f commit 631b8e0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
30 changes: 24 additions & 6 deletions Assets/Mirror/Components/NetworkTransform/NetworkTransformBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 631b8e0

Please sign in to comment.