Skip to content

Commit 30d1fb3

Browse files
fix
First pass at fixing the issue where a server authority instance would lag behind when using the new interpolators. This was especially visible when the moving body completely stopped, all state updates were processed, and then shortly later it began to move again there would be a delay between the 1st state update and the rest of the pending state updates.
1 parent c632b13 commit 30d1fb3

File tree

2 files changed

+7
-14
lines changed

2 files changed

+7
-14
lines changed

com.unity.netcode.gameobjects/Runtime/Components/Interpolator/BufferedLinearInterpolator.cs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ public void Reset(T currentValue)
192192
TimeToTargetValue = 0.0f;
193193
DeltaTime = 0.0f;
194194
m_CurrentDeltaTime = 0.0f;
195+
MaxDeltaTime = 0.0f;
196+
LastRemainingTime = 0.0f;
195197
}
196198
}
197199

@@ -292,13 +294,9 @@ private void TryConsumeFromBuffer(double renderTime, double minDeltaTime, double
292294
var potentialItemNeedsProcessing = false;
293295

294296
// In the event there is nothing left in the queue (i.e. motion/change stopped), we still need to determine if the target has been reached.
295-
if (!noStateSet && m_BufferQueue.Count == 0)
297+
if (!noStateSet && !InterpolateState.TargetReached)
296298
{
297-
if (!InterpolateState.TargetReached)
298-
{
299-
InterpolateState.TargetReached = IsApproximately(InterpolateState.CurrentValue, InterpolateState.Target.Value.Item, GetPrecision());
300-
}
301-
return;
299+
InterpolateState.TargetReached = IsApproximately(InterpolateState.CurrentValue, InterpolateState.Target.Value.Item, GetPrecision());
302300
}
303301

304302
// Continue to process any remaining state updates in the queue (if any)
@@ -314,14 +312,10 @@ private void TryConsumeFromBuffer(double renderTime, double minDeltaTime, double
314312
if (!noStateSet)
315313
{
316314
potentialItemNeedsProcessing = ((potentialItem.TimeSent <= renderTime) && potentialItem.TimeSent > InterpolateState.Target.Value.TimeSent);
317-
if (!InterpolateState.TargetReached)
318-
{
319-
InterpolateState.TargetReached = IsApproximately(InterpolateState.CurrentValue, InterpolateState.Target.Value.Item, GetPrecision());
320-
}
321315
}
322316

323317
// If we haven't set a target or we have another item that needs processing.
324-
if (noStateSet || potentialItemNeedsProcessing)
318+
if ((noStateSet && (potentialItem.TimeSent <= renderTime)) || potentialItemNeedsProcessing)
325319
{
326320
if (m_BufferQueue.TryDequeue(out BufferedItem target))
327321
{

com.unity.netcode.gameobjects/Runtime/Components/NetworkTransform.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4049,13 +4049,12 @@ public double GetPositionLastRemainingTime()
40494049
}
40504050
#endif
40514051

4052-
4053-
40544052
// Non-Authority
40554053
private void UpdateInterpolation()
40564054
{
40574055
AdjustForChangeInTransformSpace();
4058-
var timeSystem = m_CachedNetworkManager.ServerTime;
4056+
// Select the time system relative to the type of NetworkManager instance.
4057+
var timeSystem = m_CachedNetworkManager.IsServer ? m_CachedNetworkManager.ServerTime : m_CachedNetworkManager.LocalTime;
40594058
var currentTime = timeSystem.Time;
40604059
#if COM_UNITY_MODULES_PHYSICS || COM_UNITY_MODULES_PHYSICS2D
40614060
var cachedDeltaTime = m_UseRigidbodyForMotion ? m_CachedNetworkManager.RealTimeProvider.FixedDeltaTime : m_CachedNetworkManager.RealTimeProvider.DeltaTime;

0 commit comments

Comments
 (0)