Skip to content

Commit

Permalink
fix: client not tracking changes to layer weights [MTT-7166] (#2674)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
NoelStephensUnity authored Aug 23, 2023
1 parent cea4486 commit b5b8eda
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
6 changes: 5 additions & 1 deletion com.unity.netcode.gameobjects/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
19 changes: 17 additions & 2 deletions testproject/Assets/Tests/Runtime/Animation/NetworkAnimatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ------------------ ");
Expand Down

0 comments on commit b5b8eda

Please sign in to comment.