diff --git a/com.unity.netcode.gameobjects/CHANGELOG.md b/com.unity.netcode.gameobjects/CHANGELOG.md index 5ce566967d..38656d18cd 100644 --- a/com.unity.netcode.gameobjects/CHANGELOG.md +++ b/com.unity.netcode.gameobjects/CHANGELOG.md @@ -28,6 +28,7 @@ Additional documentation and release notes are available at [Multiplayer Documen ### Fixed +- Fixed memory leak in `NetworkAnimator` on clients where `RpcTarget` groups were not being properly disposed due to incorrect type casting of `ProxyRpcTargetGroup` to `RpcTargetGroup`. - Fixed issue when using a client-server topology where a `NetworkList` with owner write permissions was resetting sent time and dirty flags after having been spawned on owning clients that were not the spawn authority. (#3850) - Fixed an integer overflow that occurred when configuring a large disconnect timeout with Unity Transport. (#3810) diff --git a/com.unity.netcode.gameobjects/Runtime/Components/NetworkAnimator.cs b/com.unity.netcode.gameobjects/Runtime/Components/NetworkAnimator.cs index b939717f6d..c8db9b0d47 100644 --- a/com.unity.netcode.gameobjects/Runtime/Components/NetworkAnimator.cs +++ b/com.unity.netcode.gameobjects/Runtime/Components/NetworkAnimator.cs @@ -709,7 +709,7 @@ protected virtual bool OnIsServerAuthoritative() private static byte[] s_EmptyArray = new byte[] { }; private List m_ParametersToUpdate; private RpcParams m_RpcParams; - private RpcTargetGroup m_TargetGroup; + private IGroupRpcTarget m_TargetGroup; private AnimationMessage m_AnimationMessage; private NetworkAnimatorStateChangeHandler m_NetworkAnimatorStateChangeHandler; @@ -762,7 +762,7 @@ public override void OnDestroy() { SpawnCleanup(); - m_TargetGroup?.Dispose(); + m_TargetGroup?.Target?.Dispose(); if (m_CachedAnimatorParameters != null && m_CachedAnimatorParameters.IsCreated) { @@ -928,12 +928,12 @@ public override void OnNetworkSpawn() NetworkLog.LogWarningServer($"[{gameObject.name}][{nameof(NetworkAnimator)}] {nameof(Animator)} is not assigned! Animation synchronization will not work for this instance!"); } - m_TargetGroup = RpcTarget.Group(new List(128), RpcTargetUse.Persistent) as RpcTargetGroup; + m_TargetGroup = RpcTarget.Group(new List(128), RpcTargetUse.Persistent) as IGroupRpcTarget; m_RpcParams = new RpcParams() { Send = new RpcSendParams() { - Target = m_TargetGroup + Target = m_TargetGroup?.Target } }; @@ -1219,7 +1219,7 @@ internal void CheckForAnimatorChanges() } m_TargetGroup.Add(clientId); } - m_RpcParams.Send.Target = m_TargetGroup; + m_RpcParams.Send.Target = m_TargetGroup.Target; SendClientAnimStateRpc(m_AnimationMessage, m_RpcParams); } } @@ -1555,7 +1555,7 @@ private unsafe void SendServerParametersUpdateRpc(ParametersUpdateMessage parame m_TargetGroup.Add(clientId); } - m_RpcParams.Send.Target = m_TargetGroup; + m_RpcParams.Send.Target = m_TargetGroup.Target; m_NetworkAnimatorStateChangeHandler.SendParameterUpdate(parametersUpdate, m_RpcParams); } } @@ -1621,7 +1621,7 @@ private void SendServerAnimStateRpc(AnimationMessage animationMessage, RpcParams } m_TargetGroup.Add(clientId); } - m_RpcParams.Send.Target = m_TargetGroup; + m_RpcParams.Send.Target = m_TargetGroup.Target; m_NetworkAnimatorStateChangeHandler.SendAnimationUpdate(animationMessage, m_RpcParams); } }