Skip to content

Commit b5b8eda

Browse files
fix: client not tracking changes to layer weights [MTT-7166] (#2674)
* fix This resolves the issue with clients not keep track of changes to the layer weights. * test Validates the fix to assure clients receive weight updates and track them in order to be able to apply changes when needed.
1 parent cea4486 commit b5b8eda

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

com.unity.netcode.gameobjects/CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
77
Additional documentation and release notes are available at [Multiplayer Documentation](https://docs-multiplayer.unity3d.com).
88

99
## [Unreleased]
10+
### Added
1011

1112
### Fixed
1213

13-
- Fixed "writing past the end of the buffer" error when calling ResetDirty() on managed network variables that are larger than 256 bytes when serialized.
14+
- 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)
15+
- 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)
16+
17+
### Changed
1418

1519
## [1.5.2] - 2023-07-24
1620

com.unity.netcode.gameobjects/Components/NetworkAnimator.cs

+1
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,7 @@ internal void UpdateAnimationState(AnimationState animationState)
11371137
if (m_LayerWeights[animationState.Layer] != animationState.Weight)
11381138
{
11391139
m_Animator.SetLayerWeight(animationState.Layer, animationState.Weight);
1140+
m_LayerWeights[animationState.Layer] = animationState.Weight;
11401141
}
11411142
}
11421143

testproject/Assets/Tests/Runtime/Animation/NetworkAnimatorTests.cs

+17-2
Original file line numberDiff line numberDiff line change
@@ -495,17 +495,32 @@ public void WeightUpdateTests([Values] OwnerShipMode ownerShipMode, [Values] Aut
495495
animatorTestHelper = AnimatorTestHelper.ServerSideInstance;
496496
}
497497

498+
var originalWeight = animatorTestHelper.GetLayerWeight(1);
499+
498500
animatorTestHelper.SetLayerWeight(1, 0.75f);
499501
// Wait for all instances to update their weight value for layer 1
500502
success = WaitForConditionOrTimeOutWithTimeTravel(() => AllInstancesSameLayerWeight(ownerShipMode, 1, 0.75f));
501503
Assert.True(success, $"Timed out waiting for all instances to match weight 0.75 on layer 1!");
502504

505+
animatorTestHelper.SetLayerWeight(1, originalWeight);
506+
// Wait for all instances to update their weight value for layer 1
507+
success = WaitForConditionOrTimeOutWithTimeTravel(() => AllInstancesSameLayerWeight(ownerShipMode, 1, originalWeight));
508+
Assert.True(success, $"Timed out waiting for all instances to match weight {originalWeight} on layer 1!");
509+
510+
// Now set the layer weight to 0
511+
animatorTestHelper.SetLayerWeight(1, 0.0f);
512+
503513
// Now late join a client
504514
CreateAndStartNewClientWithTimeTravel();
505515

506516
// Verify the late joined client is synchronized to the changed weight
507-
success = WaitForConditionOrTimeOutWithTimeTravel(() => AllInstancesSameLayerWeight(ownerShipMode, 1, 0.75f));
508-
Assert.True(success, $"[Late-Join] Timed out waiting for all instances to match weight 0.75 on layer 1!");
517+
success = WaitForConditionOrTimeOutWithTimeTravel(() => AllInstancesSameLayerWeight(ownerShipMode, 1, 0.0f));
518+
Assert.True(success, $"[Late-Join] Timed out waiting for all instances to match weight 0 on layer 1!");
519+
520+
animatorTestHelper.SetLayerWeight(1, originalWeight);
521+
// Wait for all instances to update their weight value for layer 1
522+
success = WaitForConditionOrTimeOutWithTimeTravel(() => AllInstancesSameLayerWeight(ownerShipMode, 1, originalWeight));
523+
Assert.True(success, $"Timed out waiting for all instances to match weight {originalWeight} on layer 1!");
509524

510525
AnimatorTestHelper.IsTriggerTest = false;
511526
VerboseDebug($" ------------------ Weight Test [{ownerShipMode}] Stopping ------------------ ");

0 commit comments

Comments
 (0)