From e7fba516e80fd0c4d9b9bbd9508234734fb49be9 Mon Sep 17 00:00:00 2001 From: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Fri, 17 Feb 2023 11:06:42 -0600 Subject: [PATCH 1/4] fix Don't try to access m_Animator if it is not assigned. Don't try to update animation curves. --- .../Components/NetworkAnimator.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/com.unity.netcode.gameobjects/Components/NetworkAnimator.cs b/com.unity.netcode.gameobjects/Components/NetworkAnimator.cs index a942a540cf..2cea1d4da1 100644 --- a/com.unity.netcode.gameobjects/Components/NetworkAnimator.cs +++ b/com.unity.netcode.gameobjects/Components/NetworkAnimator.cs @@ -279,6 +279,11 @@ private void BuildTransitionStateInfoList() { return; } + if (m_Animator == null) + { + return; + } + TransitionStateInfoList = new List(); var animatorController = m_Animator.runtimeAnimatorController as AnimatorController; if (animatorController == null) @@ -906,6 +911,10 @@ unsafe private bool CheckParametersChanged() for (int i = 0; i < m_CachedAnimatorParameters.Length; i++) { ref var cacheValue = ref UnsafeUtility.ArrayElementAsRef(m_CachedAnimatorParameters.GetUnsafePtr(), i); + if (m_Animator.IsParameterControlledByCurve(cacheValue.Hash)) + { + continue; + } var hash = cacheValue.Hash; if (cacheValue.Type == AnimationParamEnumWrapper.AnimatorControllerParameterInt) { From 84355dd2bd72a5d51400285d004cdcc885dc330e Mon Sep 17 00:00:00 2001 From: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Fri, 17 Feb 2023 13:02:01 -0600 Subject: [PATCH 2/4] fix Now generate a tracking list for all parameters and cull out those controlled by AnimationCurves when checking for deltas. Added initial changelog entries. --- com.unity.netcode.gameobjects/CHANGELOG.md | 10 ++++++++++ .../Components/NetworkAnimator.cs | 20 ++++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/com.unity.netcode.gameobjects/CHANGELOG.md b/com.unity.netcode.gameobjects/CHANGELOG.md index bad40daedc..e9dea69111 100644 --- a/com.unity.netcode.gameobjects/CHANGELOG.md +++ b/com.unity.netcode.gameobjects/CHANGELOG.md @@ -12,6 +12,16 @@ Additional documentation and release notes are available at [Multiplayer Documen ### Changed +### Fixed +- Fixed issue where runtime association of `Animator` properties to `AnimationCurve`s would cause `NetworkAnimator` to attempt to update those changes. +- Fixed issue where `NetworkAnimator` would not check if its associated `Animator` was valid during serialization and would spam exceptions in the editor console. + +## [1.3.0] + +### Added + +### Changed + - The UTP component UI has been updated to be more user-friendly for new users by adding a simple toggle to switch between local-only (127.0.0.1) and remote (0.0.0.0) binding modes, using the toggle "Allow Remote Connections" (#2408) - Updated `UnityTransport` dependency on `com.unity.transport` to 1.3.1. - `NetworkShow()` of `NetworkObject`s are delayed until the end of the frame to ensure consistency of delta-driven variables like `NetworkList`. diff --git a/com.unity.netcode.gameobjects/Components/NetworkAnimator.cs b/com.unity.netcode.gameobjects/Components/NetworkAnimator.cs index 2cea1d4da1..ddebbc419f 100644 --- a/com.unity.netcode.gameobjects/Components/NetworkAnimator.cs +++ b/com.unity.netcode.gameobjects/Components/NetworkAnimator.cs @@ -593,17 +593,13 @@ private void Awake() m_CachedAnimatorParameters = new NativeArray(parameters.Length, Allocator.Persistent); m_ParametersToUpdate = new List(parameters.Length); + // Include all parameters including any controlled by an AnimationCurve as this could change during runtime. + // We ignore changes to any parameter controlled by an AnimationCurve when we are checking for changes in + // the Animator's parameters. for (var i = 0; i < parameters.Length; i++) { var parameter = parameters[i]; - if (m_Animator.IsParameterControlledByCurve(parameter.nameHash)) - { - // we are ignoring parameters that are controlled by animation curves - syncing the layer - // states indirectly syncs the values that are driven by the animation curves - continue; - } - var cacheParam = new AnimatorParamCache { Type = UnsafeUtility.EnumToInt(parameter.type), @@ -648,6 +644,12 @@ internal AnimationMessage GetAnimationMessage() /// public override void OnNetworkSpawn() { + // If there is no assigned Animator then generate a server network warning (logged locally and if applicable on the server-host side as well). + if (m_Animator == null) + { + NetworkLog.LogWarningServer($"[{gameObject.name}][{nameof(NetworkAnimator)}] {nameof(Animator)} is not assigned! Animation synchronization will not work for this instance!"); + } + if (IsServer) { m_ClientSendList = new List(128); @@ -911,6 +913,10 @@ unsafe private bool CheckParametersChanged() for (int i = 0; i < m_CachedAnimatorParameters.Length; i++) { ref var cacheValue = ref UnsafeUtility.ArrayElementAsRef(m_CachedAnimatorParameters.GetUnsafePtr(), i); + + // If a parameter gets controlled by a curve during runtime after initialization of NetworkAnimator + // then ignore changes to this parameter. We are not removing the parameter in the event that + // it no longer is controlled by a curve. if (m_Animator.IsParameterControlledByCurve(cacheValue.Hash)) { continue; From aeccc68f625523f7ef0e045800972a5e6e282194 Mon Sep 17 00:00:00 2001 From: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Fri, 17 Feb 2023 16:34:36 -0600 Subject: [PATCH 3/4] update Adding PR number to changelog entries. --- com.unity.netcode.gameobjects/CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/com.unity.netcode.gameobjects/CHANGELOG.md b/com.unity.netcode.gameobjects/CHANGELOG.md index e9dea69111..c57b0610bb 100644 --- a/com.unity.netcode.gameobjects/CHANGELOG.md +++ b/com.unity.netcode.gameobjects/CHANGELOG.md @@ -13,8 +13,8 @@ Additional documentation and release notes are available at [Multiplayer Documen ### Changed ### Fixed -- Fixed issue where runtime association of `Animator` properties to `AnimationCurve`s would cause `NetworkAnimator` to attempt to update those changes. -- Fixed issue where `NetworkAnimator` would not check if its associated `Animator` was valid during serialization and would spam exceptions in the editor console. +- Fixed issue where runtime association of `Animator` properties to `AnimationCurve`s would cause `NetworkAnimator` to attempt to update those changes. (#2416) +- Fixed issue where `NetworkAnimator` would not check if its associated `Animator` was valid during serialization and would spam exceptions in the editor console. (#2416) ## [1.3.0] From 609407641f6ec3697f500741a869cc8bfa8cb10c Mon Sep 17 00:00:00 2001 From: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Fri, 24 Feb 2023 17:36:39 -0600 Subject: [PATCH 4/4] changelog fix Migrating the last PR's change log into the Unreleased section. --- com.unity.netcode.gameobjects/CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/com.unity.netcode.gameobjects/CHANGELOG.md b/com.unity.netcode.gameobjects/CHANGELOG.md index 0a724d3edb..b285138e2d 100644 --- a/com.unity.netcode.gameobjects/CHANGELOG.md +++ b/com.unity.netcode.gameobjects/CHANGELOG.md @@ -13,6 +13,8 @@ Additional documentation and release notes are available at [Multiplayer Documen ### Changed ### Fixed + +- Fixed registry of public `NetworkVariable`s in derived `NetworkBehaviour`s (#2423) - Fixed issue where runtime association of `Animator` properties to `AnimationCurve`s would cause `NetworkAnimator` to attempt to update those changes. (#2416) - Fixed issue where `NetworkAnimator` would not check if its associated `Animator` was valid during serialization and would spam exceptions in the editor console. (#2416) @@ -32,7 +34,6 @@ Additional documentation and release notes are available at [Multiplayer Documen ### Fixed -- Fixed registry of public `NetworkVariable`s in derived `NetworkBehaviour`s (#2423) - Fixed issue where changes to a layer's weight would not synchronize unless a state transition was occurring.(#2399) - Fixed issue where `NetworkManager.LocalClientId` was returning the `NetworkTransport.ServerClientId` as opposed to the `NetworkManager.m_LocalClientId`. (#2398) - Fixed issue where a dynamically spawned `NetworkObject` parented under an in-scene placed `NetworkObject` would have its `InScenePlaced` value changed to `true`. This would result in a soft synchronization error for late joining clients. (#2396)