Skip to content

Commit 90d900f

Browse files
test
Renaming NetworkTransformMultipleChangesOverTime to just MultipleChangesOverTime (no need for the NetworkTransform part as it is already part of the NetworkTransformTests). Turning off Lerp smoothing for MultipleChangesOverTime and added lengthy comment as to why. Fixed the initial check for the first state update in MultipleChangesOverTime due to a change in the Interpolation value. It was not properly checking both pushed and updated values and should only be checked when interpolation is turned off as the default is enabled and when running MultipleChangesOverTime for 3 axis it remains enabled (i.e. there will be no state update for that as nothing changed).
1 parent 35b7fbe commit 90d900f

File tree

2 files changed

+70
-7
lines changed

2 files changed

+70
-7
lines changed

com.unity.netcode.gameobjects/Tests/Runtime/NetworkTransform/NetworkTransformBase.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,7 @@ internal class NetworkTransformTestComponent : NetworkTransform
782782

783783
protected override void OnAuthorityPushTransformState(ref NetworkTransformState networkTransformState)
784784
{
785+
Debug.Log($"[Auth]{name} State Pushed.");
785786
StatePushed = true;
786787
AuthorityLastSentState = networkTransformState;
787788
AuthorityPushedTransformState?.Invoke(ref networkTransformState);
@@ -792,10 +793,41 @@ protected override void OnAuthorityPushTransformState(ref NetworkTransformState
792793
public bool StateUpdated { get; internal set; }
793794
protected override void OnNetworkTransformStateUpdated(ref NetworkTransformState oldState, ref NetworkTransformState newState)
794795
{
796+
Debug.Log($"[Non-Auth]{name} State Updated.");
795797
StateUpdated = true;
796798
base.OnNetworkTransformStateUpdated(ref oldState, ref newState);
797799
}
798800

801+
protected string GetVector3Values(ref Vector3 vector3)
802+
{
803+
return $"({vector3.x:F6},{vector3.y:F6},{vector3.z:F6})";
804+
}
805+
806+
protected string GetVector3Values(Vector3 vector3)
807+
{
808+
return GetVector3Values(ref vector3);
809+
}
810+
811+
public bool EnableVerboseDebug;
812+
813+
public void GetInterpolatorInfo()
814+
{
815+
if (!EnableVerboseDebug)
816+
{
817+
return;
818+
}
819+
var positionInterpolator = GetPositionInterpolator();
820+
var rotationInterpolator = GetRotationInterpolator();
821+
Debug.Log($"TT: {positionInterpolator.InterpolateState.TimeToTargetValue} BuffCnt: {positionInterpolator.m_BufferQueue.Count} Pos: {GetVector3Values(positionInterpolator.InterpolateState.CurrentValue)} " +
822+
$"Rot: {GetVector3Values(rotationInterpolator.InterpolateState.CurrentValue.eulerAngles)}");
823+
}
824+
825+
public override void OnUpdate()
826+
{
827+
base.OnUpdate();
828+
GetInterpolatorInfo();
829+
}
830+
799831
protected override bool OnIsServerAuthoritative()
800832
{
801833
return ServerAuthority;

com.unity.netcode.gameobjects/Tests/Runtime/NetworkTransform/NetworkTransformTests.cs

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ public void ParentedNetworkTransformTest([Values] Interpolation interpolation, [
492492
/// delta update, and it runs through 8 delta updates per unique test.
493493
/// </remarks>
494494
[Test]
495-
public void NetworkTransformMultipleChangesOverTime([Values] TransformSpace testLocalTransform, [Values] OverrideState overideState, [Values] Axis axis)
495+
public void MultipleChangesOverTime([Values] TransformSpace testLocalTransform, [Values] OverrideState overideState, [Values] Axis axis)
496496
{
497497
m_AuthoritativeTransform.InLocalSpace = testLocalTransform == TransformSpace.Local;
498498
bool axisX = axis == Axis.X || axis == Axis.XY || axis == Axis.XZ || axis == Axis.XYZ;
@@ -507,6 +507,30 @@ public void NetworkTransformMultipleChangesOverTime([Values] TransformSpace test
507507
// when interpolation is enabled.
508508
m_AuthoritativeTransform.Interpolate = axisCount == 3 ? true : false;
509509

510+
// Lerp smoothing skews values based on our tests and how we had to originally adjust for the way we handled the original Lerp approach and how that
511+
// consumed state updates from the buffer.
512+
// With the two new interpolation types, they will process until close to the final value before moving on to the next.
513+
// Lerp--> Will skip to next state before finishing the current state (i.e. loss of precision but arrives to the final value at the end of multiple updates faster)
514+
// LerpExtrapolateBlend & SmoothDampening -->
515+
// Will not skip to the next state update until approximately at the end of the current state (higher precision longer time to final value)
516+
// How this impacts this test:
517+
// It was re-written to use TimeTravel which has a limit of 60 update iterations per "WaitforCondition" which if you are interpolating between two large values
518+
// it can take a few more iterations with lerp smoothing enabled. Lerp smoothing is purely a visual thing and will eventually end up at its final destination
519+
// upon processing the last state update. However, this test should be only to verify the functionality of the actual lerping between values without the added
520+
// delay of smoothing the final result. So, instead of having one timeout value for the two new interpolation types and the default for the original I am opting
521+
// for the disabling of lerp smoothing while this particular test runs as it really is only validating that each interpolator type will interpolate to the right
522+
// value within a given period of time which is simulated using the time travel approach.
523+
// With smooth lerping enabled, the two new interpolation types will come very close to the correct value but will not reach the 2nd or 3rd pass values set because
524+
// this test uses the adjusted approximation checks that prematurely determines the target values (position, rotation, and scale) have been reached and as such
525+
// sends a new state update that will sit in the buffer for 3-4 frames before the two new interpolation types are done with the current state update. This will
526+
// eventually lead to a time deficit that will offset the processing of the next state update such that the default time travel timeout (60 updates) will timeout
527+
// and the test will fail. This only happens with 3 axis since that is the only time interpolation was enabled for this particular test.
528+
// As such, just disabling smooth lerping for all 3 seemed like the better approach as the maximum interpolation time out period for smooth lerping is now
529+
// adjustable by users (i.e. they can adjust how much lerp smoothing is applied based on their project's needs).
530+
m_NonAuthoritativeTransform.PositionLerpSmoothing = false;
531+
m_NonAuthoritativeTransform.RotationLerpSmoothing = false;
532+
m_NonAuthoritativeTransform.ScaleLerpSmoothing = false;
533+
510534
m_CurrentAxis = axis;
511535

512536
m_AuthoritativeTransform.SyncPositionX = axisX;
@@ -541,12 +565,18 @@ public void NetworkTransformMultipleChangesOverTime([Values] TransformSpace test
541565
var scale = scaleStart;
542566
var success = false;
543567

544-
m_AuthoritativeTransform.StatePushed = false;
545-
// Wait for the deltas to be pushed
546-
WaitForConditionOrTimeOutWithTimeTravel(() => m_AuthoritativeTransform.StatePushed);
547-
// Allow the precision settings to propagate first as changing precision
548-
// causes a teleport event to occur
549-
TimeTravelAdvanceTick();
568+
// The default is interpolate, so we only need to check for the updated state when
569+
// we turn off interpolation.
570+
if (!m_AuthoritativeTransform.Interpolate)
571+
{
572+
// Reset our state updated and state pushed
573+
m_NonAuthoritativeTransform.StateUpdated = false;
574+
m_AuthoritativeTransform.StatePushed = false;
575+
// Wait for both authority and non-authority to update their respective flags so we know the change to interpolation has been received.
576+
success = WaitForConditionOrTimeOutWithTimeTravel(() => m_AuthoritativeTransform.StatePushed && m_NonAuthoritativeTransform.StateUpdated);
577+
Assert.True(success, "Failed to wait for interpolation changed state update!");
578+
}
579+
550580
var iterations = axisCount == 3 ? k_PositionRotationScaleIterations3Axis : k_PositionRotationScaleIterations;
551581

552582
// Move and rotate within the same tick, validate the non-authoritative instance updates
@@ -595,6 +625,7 @@ public void NetworkTransformMultipleChangesOverTime([Values] TransformSpace test
595625
if (!success)
596626
{
597627
m_EnableVerboseDebug = true;
628+
VerboseDebug($"Failed on iteration: {i}");
598629
success = PositionRotationScaleMatches();
599630
m_EnableVerboseDebug = false;
600631
}

0 commit comments

Comments
 (0)