Skip to content

Commit 38fe8c2

Browse files
test fix
Adding wait for FixedUpdate in ServerAuthoritativeTest when using rigid body for motion.
1 parent beebcd6 commit 38fe8c2

1 file changed

Lines changed: 20 additions & 6 deletions

File tree

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

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ protected override void OnServerAndClientsCreated()
4040
clientNetworkTransform.UseHalfFloatPrecision = false;
4141
var rigidBody = m_ClientNetworkTransformPrefab.AddComponent<Rigidbody>();
4242
rigidBody.useGravity = false;
43+
rigidBody.interpolation = RigidbodyInterpolation.None;
4344
// NOTE: We don't use a sphere collider for this integration test because by the time we can
4445
// assure they don't collide and skew the results the NetworkObjects are already synchronized
4546
// with skewed results
@@ -51,6 +52,7 @@ protected override void OnServerAndClientsCreated()
5152
var networkTransform = m_NetworkTransformPrefab.AddComponent<NetworkTransform>();
5253
rigidBody = m_NetworkTransformPrefab.AddComponent<Rigidbody>();
5354
rigidBody.useGravity = false;
55+
rigidBody.interpolation = RigidbodyInterpolation.None;
5456
// NOTE: We don't use a sphere collider for this integration test because by the time we can
5557
// assure they don't collide and skew the results the NetworkObjects are already synchronized
5658
// with skewed results
@@ -281,12 +283,7 @@ public IEnumerator OwnerAuthoritativeTest([Values] StartingOwnership startingOwn
281283
ownerInstance.transform.localScale = valueSetByOwner;
282284
rotation.eulerAngles = valueSetByOwner;
283285

284-
yield return s_DefaultWaitForTick;
285-
// Allow scale to update first when using rigid body motion
286-
if (m_MotionModel == MotionModels.UseRigidbody)
287-
{
288-
yield return new WaitForFixedUpdate();
289-
}
286+
290287

291288
Vector3 GetNonOwnerPosition()
292289
{
@@ -324,6 +321,12 @@ Quaternion GetNonOwnerRotation()
324321
ownerInstance.transform.position = valueSetByOwner;
325322
ownerInstance.transform.rotation = rotation;
326323
}
324+
325+
// Allow scale to update first when using rigid body motion
326+
if (m_MotionModel == MotionModels.UseRigidbody)
327+
{
328+
yield return new WaitForFixedUpdate();
329+
}
327330

328331
yield return WaitForConditionOrTimeOut(() => Approximately(GetNonOwnerPosition(), valueSetByOwner) && Approximately(transformToTest.localScale, valueSetByOwner) && Approximately(GetNonOwnerRotation(), rotation));
329332
Assert.False(s_GlobalTimeoutHelper.TimedOut, $"Timed out waiting for {networkManagerNonOwner.name}'s object instance {nonOwnerInstance.name} to change its transform!\n" +
@@ -334,6 +337,11 @@ Quaternion GetNonOwnerRotation()
334337
// The last check is to verify non-owners cannot change transform values after ownership has changed
335338
nonOwnerInstance.transform.position = Vector3.zero;
336339
yield return s_DefaultWaitForTick;
340+
// Allow scale to update first when using rigid body motion
341+
if (m_MotionModel == MotionModels.UseRigidbody)
342+
{
343+
yield return new WaitForFixedUpdate();
344+
}
337345
Assert.True(Approximately(GetNonOwnerPosition(), valueSetByOwner), $"{networkManagerNonOwner.name}'s object instance {nonOwnerInstance.name} was allowed to change its position! Expected: {valueSetByOwner} Is Currently:{GetNonOwnerPosition()}");
338346
}
339347

@@ -366,6 +374,12 @@ public IEnumerator ServerAuthoritativeTest()
366374
eulerAngles = valueSetByOwner
367375
};
368376
ownerInstance.transform.rotation = rotation;
377+
378+
// Allow scale to update first when using rigid body motion
379+
if (m_MotionModel == MotionModels.UseRigidbody)
380+
{
381+
yield return new WaitForFixedUpdate();
382+
}
369383
var transformToTest = nonOwnerInstance.transform;
370384
yield return WaitForConditionOrTimeOut(() => transformToTest.position == valueSetByOwner && transformToTest.localScale == valueSetByOwner && transformToTest.rotation == rotation);
371385
Assert.False(s_GlobalTimeoutHelper.TimedOut, $"Timed out waiting for {m_ClientNetworkManagers[0].name}'s object instance {nonOwnerInstance.name} to change its transform!\n" +

0 commit comments

Comments
 (0)