Skip to content

Commit 8b8825b

Browse files
fix: NetworkAnimator generating AnimationCurve warnings (#2416)
* fix Don't try to access m_Animator if it is not assigned. Don't try to update animation curves. Now generate a tracking list for all parameters and cull out those controlled by AnimationCurves when checking for deltas.
1 parent fda40c3 commit 8b8825b

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

com.unity.netcode.gameobjects/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Additional documentation and release notes are available at [Multiplayer Documen
1515
### Fixed
1616

1717
- Fixed registry of public `NetworkVariable`s in derived `NetworkBehaviour`s (#2423)
18+
- Fixed issue where runtime association of `Animator` properties to `AnimationCurve`s would cause `NetworkAnimator` to attempt to update those changes. (#2416)
19+
- Fixed issue where `NetworkAnimator` would not check if its associated `Animator` was valid during serialization and would spam exceptions in the editor console. (#2416)
1820

1921
### Removed
2022

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

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,11 @@ private void BuildTransitionStateInfoList()
279279
{
280280
return;
281281
}
282+
if (m_Animator == null)
283+
{
284+
return;
285+
}
286+
282287
TransitionStateInfoList = new List<TransitionStateinfo>();
283288
var animatorController = m_Animator.runtimeAnimatorController as AnimatorController;
284289
if (animatorController == null)
@@ -588,17 +593,13 @@ private void Awake()
588593
m_CachedAnimatorParameters = new NativeArray<AnimatorParamCache>(parameters.Length, Allocator.Persistent);
589594
m_ParametersToUpdate = new List<int>(parameters.Length);
590595

596+
// Include all parameters including any controlled by an AnimationCurve as this could change during runtime.
597+
// We ignore changes to any parameter controlled by an AnimationCurve when we are checking for changes in
598+
// the Animator's parameters.
591599
for (var i = 0; i < parameters.Length; i++)
592600
{
593601
var parameter = parameters[i];
594602

595-
if (m_Animator.IsParameterControlledByCurve(parameter.nameHash))
596-
{
597-
// we are ignoring parameters that are controlled by animation curves - syncing the layer
598-
// states indirectly syncs the values that are driven by the animation curves
599-
continue;
600-
}
601-
602603
var cacheParam = new AnimatorParamCache
603604
{
604605
Type = UnsafeUtility.EnumToInt(parameter.type),
@@ -643,6 +644,12 @@ internal AnimationMessage GetAnimationMessage()
643644
/// <inheritdoc/>
644645
public override void OnNetworkSpawn()
645646
{
647+
// If there is no assigned Animator then generate a server network warning (logged locally and if applicable on the server-host side as well).
648+
if (m_Animator == null)
649+
{
650+
NetworkLog.LogWarningServer($"[{gameObject.name}][{nameof(NetworkAnimator)}] {nameof(Animator)} is not assigned! Animation synchronization will not work for this instance!");
651+
}
652+
646653
if (IsServer)
647654
{
648655
m_ClientSendList = new List<ulong>(128);
@@ -906,6 +913,14 @@ unsafe private bool CheckParametersChanged()
906913
for (int i = 0; i < m_CachedAnimatorParameters.Length; i++)
907914
{
908915
ref var cacheValue = ref UnsafeUtility.ArrayElementAsRef<AnimatorParamCache>(m_CachedAnimatorParameters.GetUnsafePtr(), i);
916+
917+
// If a parameter gets controlled by a curve during runtime after initialization of NetworkAnimator
918+
// then ignore changes to this parameter. We are not removing the parameter in the event that
919+
// it no longer is controlled by a curve.
920+
if (m_Animator.IsParameterControlledByCurve(cacheValue.Hash))
921+
{
922+
continue;
923+
}
909924
var hash = cacheValue.Hash;
910925
if (cacheValue.Type == AnimationParamEnumWrapper.AnimatorControllerParameterInt)
911926
{

0 commit comments

Comments
 (0)