Skip to content

fix: late time sync no longer steps client time back (#4249) - #4262

Open
NoelStephensUnity wants to merge 2 commits into
develop-3.x.xfrom
fix/time-no-backward-hard-reset
Open

NoelStephensUnity wants to merge 2 commits into
develop-3.x.xfrom
fix/time-no-backward-hard-reset

Conversation

@NoelStephensUnity

@NoelStephensUnity NoelStephensUnity commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

Purpose of this PR

A late time sync no longer steps a client's network time back, and a NetworkTransform keeps sending state updates if the time does step back.

Fixes #4249.

What needed fixing: a time sync that arrives late (a resend under packet loss, or one read after a long frame) makes the server look further behind than it is. When the gap passed HardResetThresholdSec (0.2 s), NetworkTimeSystem.Advance hard-reset the client's time backwards. Owner authoritative NetworkTransforms skipped every tick at or below the last one sent, so they sent no state updates until the client's time caught up again.

What changes:

  • NetworkTimeSystem.Advance only hard-resets forward. When a sync puts the desired time more than HardResetThresholdSec behind, time slows down by AdjustmentRatio until it catches up. Reset() can still step time back.
  • NetworkTransform skips only a repeated tick. If the tick goes back, it keeps sending with ticks above the last one sent, so non-authority instances do not drop the states as old.

TimeSyncMessage stays reliable (all messages share one delivery so NetworkMessageManager keeps their order).

PR Scope:

  • NetworkTimeSystem hard reset direction.
  • NetworkTransform tick gate.

Jira ticket:

MTT-16795

Changelog

  • Fixed: Issue where a time sync that arrived late could step a client's network time back, so the NetworkTransforms it owns sent no state updates until its time caught up again. A late time sync now slows the client's time down instead, and a NetworkTransform keeps sending with increasing ticks if the time does step back.

Documentation

  • No documentation changes or additions were necessary.

Testing & QA (How your changes can be verified during release Playtest)

Functional Testing

Manual testing :

  • Manual testing done
    • Stress test under simulated latency and using relay.
    • Owner authoritative character controller tested using the same conditions.

Automated tests:

  • Covered by existing automated tests
  • Covered by new automated tests

New tests: ClientNetworkTimeSystemTests (late sync slows time instead of stepping back, forward reset, Reset can step back) and NetworkTransformClockStepBackTests.OwnerKeepsSendingAfterClockStepsBack.

Does the change require QA team to:

  • Review automated tests?
  • Execute manual tests?
  • Provide feedback about the PR?

Up-port

N/A (targets develop-3.x.x).

Backports

#4263

NetworkTimeSystem.Advance only hard-resets forward. A sync that puts the
desired time more than HardResetThresholdSec behind now slews back at
AdjustmentRatio instead. Reset() can still step time back.

NetworkTransform's tick driver skips only a repeated tick; if the tick goes
back it keeps sending with ticks above the last one sent, so receivers do
not drop the states.
@NoelStephensUnity NoelStephensUnity added the port:2.x-needed This issue needs to be ported to 2.X branch label Nov 30, 2026
@NoelStephensUnity
NoelStephensUnity marked this pull request as ready for review November 30, 2026 17:55
@NoelStephensUnity
NoelStephensUnity requested a review from a team as a code owner November 30, 2026 17:55

@u-pr u-pr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Harness Review

Ship it

The change prevents backward hard resets during normal time advancement and keeps transform updates sending after a clock rollback. I examined the offset rebasing, tick dispatch, receiver timestamp handling, ownership transitions, added regression tests, and changelog; no actionable issues surfaced.

Reviewed commit 503e943

🤖 Helpful? 👍/👎

@NoelStephensUnity NoelStephensUnity added port:2.x-completed This issue was ported to 2.X branch and removed port:2.x-needed This issue needs to be ported to 2.X branch labels Nov 30, 2026
@codecov-github-com

codecov-github-com Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

@@                Coverage Diff                @@
##           develop-3.x.x    #4262      +/-   ##
=================================================
+ Coverage          76.72%   76.73%   +0.01%     
=================================================
  Files                159      159              
  Lines              28101    28116      +15     
=================================================
+ Hits               21561    21576      +15     
  Misses              6540     6540              
Flag Coverage Δ
NGOv2_project_testproject_ubuntu 75.77% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...gameobjects/Runtime/Components/NetworkTransform.cs 88.98% <100.00%> (+0.01%) ⬆️
...de.gameobjects/Runtime/Timing/NetworkTimeSystem.cs 95.57% <100.00%> (+0.47%) ⬆️
Components Coverage Δ
com.unity.netcode.gameobjects 76.73% <100.00%> (+0.01%) ⬆️

ℹ️ Need help interpreting these results?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

port:2.x-completed This issue was ported to 2.X branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TimeSyncMessage is sent reliably, so a late one resets the client clock backwards and stalls its NetworkTransforms

2 participants