Skip to content

fix: Lerp smoothing frame rate dependence and freeze at maximum interpolation time - #4130

Open
NoelStephensUnity wants to merge 3 commits into
develop-2.0.0from
fix/interpolator-lerp-smoothing-framerate
Open

fix: Lerp smoothing frame rate dependence and freeze at maximum interpolation time#4130
NoelStephensUnity wants to merge 3 commits into
develop-2.0.0from
fix/interpolator-lerp-smoothing-framerate

Conversation

@NoelStephensUnity

@NoelStephensUnity NoelStephensUnity commented Aug 19, 2026

Copy link
Copy Markdown
Member

Purpose of this PR

Fixes two pre-existing defects in the lerp smoothing pass used by the Lerp and SmoothDampening interpolation types.

1. Smoothing was frame rate dependent. The factor was 1.0f - MaximumInterpolationTime applied once per frame with no delta time, so the wall clock smoothing rate scaled with the frame rate. It is now raised to the number of 60fps reference frames elapsed, making the rate a function of elapsed time.

2. A maximum interpolation time of 1.0 froze the transform. That is the upper bound of the inspector [Range], and it produced a factor of exactly 0, so the value never advanced. Affects all three axes and both interpolation types. The retained portion is now clamped just below 1.0.

Three things worth knowing that aren't obvious from the diff:

  • Results at 60fps are byte-identical for every legal setting except 1.0. Verified across 0.1 / 0.5 / 0.9 / 0.99. Only 1.0 changes, and it was a hard freeze, so nothing could have been relying on it. Other frame rates now match the 60fps curve rather than diverging from it.
  • The blast radius is smaller than it looks. InterpolationTypes.LegacyLerp is enum value 0 with no field initializer, no Reset(), and no editor default, so a freshly added NetworkTransform uses the legacy path — which was already frame rate correct and is untouched here. Only projects that explicitly opted into Lerp or SmoothDampening were exposed.
  • The two defects are independent, which is why there are two constants rather than one fix. pow(1.0, x) == 1, so the delta time fix alone still yields a factor of 0 at 1.0.

For scale: settle time at MaxInterpolationTime = 0.9 was 2.13s @30fps vs 0.275s @240FPS; it is now a flat ~1.02s at 30/60/120/240. At the 0.1 default the effect was invisible, which is why this went unnoticed.

The doc comments on the lerp smoothing fields described the LegacyLerp formula for all interpolation types and have been corrected.

Jira ticket

TODO: add ticket

Changelog

com.unity.netcode.gameobjects

  • Fixed: Issue where lerp smoothing was applied per frame instead of over time, which caused the Lerp and SmoothDampening interpolation types to smooth by different amounts at different frame rates. Results at 60fps are unchanged.
  • Fixed: Issue where setting a maximum interpolation time of 1.0 would stop a NetworkTransform from interpolating at all when using the Lerp or SmoothDampening interpolation types.

Documentation

  • Includes edits to existing public API documentation.

The remarks on PositionLerpSmoothing, RotationLerpSmoothing, ScaleLerpSmoothing, MaximumInterpolationTime, and the InterpolationTypes.Lerp / SmoothDampening enum entries all described the LegacyLerp formula regardless of the selected type. They now state that smoothing is frame rate independent and note that the same value does not produce the same result under LegacyLerp as under the other types.

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

Both regression tests were written first and confirmed red against unfixed code, failing on the intended assertions rather than on timeouts:

  • freeze: Interpolated value only advanced 0 from 3.17 over 2.11s (once for Lerp, once for SmoothDampening)
  • frame rate: produced 6.626402 at 30fps but 6.688997 at 240fps

After the fix, all 13 tests in InterpolatorTests pass, including the 10 pre-existing ones.

For release playtest, the highest value check is an object using Lerp or SmoothDampening with a maximum interpolation time above ~0.5, observed at a non-60fps frame rate — that is where the old and new behaviour differ. At the 0.1 default there should be no perceptible change at any frame rate.

Functional Testing

Manual testing :

  • Manual testing done

Automated tests:

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

Does the change require QA team to:

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

Up-port

#4132 is the up-port.
Required. Will be up-ported to develop-3.x.x once this PR lands.

Backports

Not needed.

…polation time

The lerp smoothing pass used by the Lerp and SmoothDampening interpolation
types applied a fixed factor of 1.0 minus the maximum interpolation time once
per frame, with no delta time. The wall clock smoothing rate therefore scaled
with the frame rate, so the same setting smoothed by different amounts on
different hardware. The factor is now raised to the number of 60fps reference
frames elapsed, which makes the rate a function of elapsed time. Results at
60fps are unchanged for every legal setting.

Separately, a maximum interpolation time of 1.0 (the upper bound of the
inspector range) produced a factor of exactly 0, so the interpolated value
never advanced and the transform stopped moving entirely on all three axes.
The retained portion is now clamped just below 1.0. This is an independent
defect, as raising 1.0 to any power is still 1.0.

The LegacyLerp path was already frame rate correct and is unchanged. The
documentation on the lerp smoothing fields described the LegacyLerp formula
for all interpolation types and has been corrected.
updating the PR number.
@NoelStephensUnity
NoelStephensUnity marked this pull request as ready for review August 19, 2026 01:33
@NoelStephensUnity
NoelStephensUnity requested a review from a team as a code owner August 19, 2026 01:33
@codecov-github-com

codecov-github-com Bot commented Aug 19, 2026

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

@@                Coverage Diff                @@
##           develop-2.0.0    #4130      +/-   ##
=================================================
+ Coverage          73.86%   73.96%   +0.09%     
=================================================
  Files                172      172              
  Lines              28099    28103       +4     
=================================================
+ Hits               20756    20786      +30     
+ Misses              7343     7317      -26     
Flag Coverage Δ
NGOv2_project_testproject_ubuntu_pinnedTrunk 73.68% <100.00%> (?)

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

Files with missing lines Coverage Δ
...ponents/Interpolator/BufferedLinearInterpolator.cs 86.46% <100.00%> (+0.15%) ⬆️
...gameobjects/Runtime/Components/NetworkTransform.cs 88.42% <ø> (ø)

... and 2 files with indirect coverage changes

Components Coverage Δ
com.unity.netcode.gameobjects 73.96% <100.00%> (+0.09%) ⬆️

ℹ️ Need help interpreting these results?

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant