diff --git a/com.unity.netcode.gameobjects/CHANGELOG.md b/com.unity.netcode.gameobjects/CHANGELOG.md index 1f09ae882e..a85d578e27 100644 --- a/com.unity.netcode.gameobjects/CHANGELOG.md +++ b/com.unity.netcode.gameobjects/CHANGELOG.md @@ -7,10 +7,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) Additional documentation and release notes are available at [Multiplayer Documentation](https://docs-multiplayer.unity3d.com). ## [Unreleased] +### Added ### Fixed -- Fixed "writing past the end of the buffer" error when calling ResetDirty() on managed network variables that are larger than 256 bytes when serialized. +- Fixed issue where `NetworkAnimator` was not internally tracking changes to layer weights which prevented proper layer weight synchronization back to the original layer weight value. (#2674) +- Fixed "writing past the end of the buffer" error when calling ResetDirty() on managed network variables that are larger than 256 bytes when serialized. (#2670) + +### Changed ## [1.5.2] - 2023-07-24 diff --git a/com.unity.netcode.gameobjects/Components/NetworkAnimator.cs b/com.unity.netcode.gameobjects/Components/NetworkAnimator.cs index 64f6017da8..538b4b9c88 100644 --- a/com.unity.netcode.gameobjects/Components/NetworkAnimator.cs +++ b/com.unity.netcode.gameobjects/Components/NetworkAnimator.cs @@ -1137,6 +1137,7 @@ internal void UpdateAnimationState(AnimationState animationState) if (m_LayerWeights[animationState.Layer] != animationState.Weight) { m_Animator.SetLayerWeight(animationState.Layer, animationState.Weight); + m_LayerWeights[animationState.Layer] = animationState.Weight; } } diff --git a/testproject/Assets/Tests/Runtime/Animation/NetworkAnimatorTests.cs b/testproject/Assets/Tests/Runtime/Animation/NetworkAnimatorTests.cs index 14e299b443..8061ce8de4 100644 --- a/testproject/Assets/Tests/Runtime/Animation/NetworkAnimatorTests.cs +++ b/testproject/Assets/Tests/Runtime/Animation/NetworkAnimatorTests.cs @@ -495,17 +495,32 @@ public void WeightUpdateTests([Values] OwnerShipMode ownerShipMode, [Values] Aut animatorTestHelper = AnimatorTestHelper.ServerSideInstance; } + var originalWeight = animatorTestHelper.GetLayerWeight(1); + animatorTestHelper.SetLayerWeight(1, 0.75f); // Wait for all instances to update their weight value for layer 1 success = WaitForConditionOrTimeOutWithTimeTravel(() => AllInstancesSameLayerWeight(ownerShipMode, 1, 0.75f)); Assert.True(success, $"Timed out waiting for all instances to match weight 0.75 on layer 1!"); + animatorTestHelper.SetLayerWeight(1, originalWeight); + // Wait for all instances to update their weight value for layer 1 + success = WaitForConditionOrTimeOutWithTimeTravel(() => AllInstancesSameLayerWeight(ownerShipMode, 1, originalWeight)); + Assert.True(success, $"Timed out waiting for all instances to match weight {originalWeight} on layer 1!"); + + // Now set the layer weight to 0 + animatorTestHelper.SetLayerWeight(1, 0.0f); + // Now late join a client CreateAndStartNewClientWithTimeTravel(); // Verify the late joined client is synchronized to the changed weight - success = WaitForConditionOrTimeOutWithTimeTravel(() => AllInstancesSameLayerWeight(ownerShipMode, 1, 0.75f)); - Assert.True(success, $"[Late-Join] Timed out waiting for all instances to match weight 0.75 on layer 1!"); + success = WaitForConditionOrTimeOutWithTimeTravel(() => AllInstancesSameLayerWeight(ownerShipMode, 1, 0.0f)); + Assert.True(success, $"[Late-Join] Timed out waiting for all instances to match weight 0 on layer 1!"); + + animatorTestHelper.SetLayerWeight(1, originalWeight); + // Wait for all instances to update their weight value for layer 1 + success = WaitForConditionOrTimeOutWithTimeTravel(() => AllInstancesSameLayerWeight(ownerShipMode, 1, originalWeight)); + Assert.True(success, $"Timed out waiting for all instances to match weight {originalWeight} on layer 1!"); AnimatorTestHelper.IsTriggerTest = false; VerboseDebug($" ------------------ Weight Test [{ownerShipMode}] Stopping ------------------ ");