Skip to content

Conversation

@michalChrobot
Copy link
Member

@michalChrobot michalChrobot commented Jan 28, 2026

Purpose of this PR

This PR aims to resolve a memory leak issue reported in #3852

The bug was a memory leak in NetworkAnimator on clients due to RpcTarget not being properly disposed.
The cause of it was that in NetworkAnimator.OnNetworkSpawn(), the code cast the result of RpcTarget.Group() to RpcTargetGroup. On clients, RpcTarget.Group() returns a ProxyRpcTargetGroup (not RpcTargetGroup), so the cast returned null. The ProxyRpcTargetGroup with its NativeList<ulong> (allocated with Allocator.Persistent) was then leaked.
The fix was to change m_TargetGroup to use the IGroupRpcTarget interface (which both RpcTargetGroup and ProxyRpcTargetGroup implement)

By using IGroupRpcTarget (the interface both implement), m_TargetGroup can now hold:

  • RpcTargetGroup when running on server
  • ProxyRpcTargetGroup when running on client

The code only uses interface methods (Add(), Clear(), Target), so it works correctly regardless of which concrete class is stored.

Jira ticket

https://jira.unity3d.com/browse/UUM-133278

Changelog

  • Fixed: memory leak in NetworkAnimator on clients where RpcTarget groups were not being properly disposed due to incorrect type casting of ProxyRpcTargetGroup to RpcTargetGroup.

Documentation

N/A

Testing & QA (How your changes can be verified during release Playtest)

I confirmed that when using latest develop-2.0.0 the issue was reproducible in the project but is not reproducible when using this branch

Backports

N/A

@michalChrobot michalChrobot changed the title Fixed issue of RpcTarget not being properly disposed. fix: Fixed issue of RpcTarget not being properly disposed. Jan 28, 2026
@michalChrobot michalChrobot changed the title fix: Fixed issue of RpcTarget not being properly disposed. fix: Fixed issue of RpcTarget not being properly disposed Jan 28, 2026
@michalChrobot michalChrobot marked this pull request as ready for review January 28, 2026 13:38
@michalChrobot michalChrobot requested a review from a team as a code owner January 28, 2026 13:38
Copy link
Member

@EmandM EmandM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is brilliant! Thanks for finding the fix!

Copy link
Member

@NoelStephensUnity NoelStephensUnity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix!

@NoelStephensUnity NoelStephensUnity merged commit 3491f14 into develop-2.0.0 Jan 28, 2026
33 of 35 checks passed
@NoelStephensUnity NoelStephensUnity deleted the fix-issue-3852 branch January 28, 2026 22:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants