com.unity.netcode.gameobjects icon indicating copy to clipboard operation
com.unity.netcode.gameobjects copied to clipboard

NetworkAnimator (If there are more than 58 variables in the animator, an error)

Open Royal2022 opened this issue 1 year ago • 1 comments

Description

If there are more than 58 variables in the animator, an error appears when connecting the second player. Also, if the variables are less than 58, then there are no errors.

Error: [Netcode] Player(Clone) threw an exception during synchronization serialization, this NetworkBehaviour is being skipped and will not be synchronized!

Reproduce Steps

  1. Create a project in Unity 6 preview.
  2. Install "Netcode for GameObjects 2.0.0" and "Multiplayer Play Mode 1.3.0" from the Package Manager.
  3. Create an object and attach the "Network Manager" component, select "Unity Transport" in the Network Transport.
  4. Create Player prefab and connect the following components to it: "Animator", "Network Object", "Network Transform", and "Network Animator", and then connect "Animator" to "Network Animator". Then in the "Animator" component create more than 59 variables.
  5. Attach the created prefab to the object with the "Network Manager" component and create a script for hosting and connection.
  6. Then host on the first one, and connect on the second one
  7. After connecting the client, an error will appear on the host side

Actual Outcome

On the client side, the host character does not display animation correctly.
And the host gets an error in the console

Expected Outcome

The animation is displayed correctly when connected, if the variables in the animator are less than or equal to 58, then everything is displayed correctly

Screenshots

Character animation when an error occurs: Снимок экрана 2024-10-11 141439

Character animation when there is no error: Снимок экрана 2024-10-11 141612

Screenshot of the error: Снимок экрана 2024-10-11 141520

Environment

  • OS: Windows 11 Pro (Version: 23H2; Build: 22631.4169)
  • Unity Version: 6000.0.22f1
  • Netcode Version: Netcode for GameObjects 2.0.0; Multiplayer Play Mode 1.3.0

Additional Context

A project with an example of an error: https://github.com/Royal2022/TEST-ERROR-PROJECT.git

Royal2022 avatar Oct 11 '24 12:10 Royal2022

Hi @Royal2022,

I have confirmed the issue and a fix for this will be included in the release after the up-coming 2.1.1 release (which will be very soon).

This is a legacy limitation set on NetworkAnimator that only provides up to 32 float values (or rather 256 bytes of information). When parameters are serialized, they include the total count of parameters as an uint bitpacked and then for each parameter a bitpacked uint as the index and then the bitpacked value of the parameter (in this case it looks like a bool)...which would mean you would reach around 58-59 parameters (including the count at the start of the serialized stream) before it would run out of write space. This would cause the exception, which would skip the synchronization (in order to not break the entire synchronization process).

As a side note, you can turn on developer logging to get extended information about errors...which in this case it provided the entire stack trace.

Needless to say, this definitely can be improved by calculating the maximum number of parameters needed during validation so it will always have the enough write buffer room for serializing the parameter values.

Thank you for providing the replication project as it greatly expedited the time it took me to track down this issue! Once I merge the PR fix for this into the develop-2.0.0 branch I will post back here with a git link you can use in your manifest file so you can get unblocked while you wait for the next versioned package.

Cheers,

Noel

NoelStephensUnity avatar Oct 19 '24 02:10 NoelStephensUnity

@Royal2022 Ok, if you replace your com.unity.netcode.gameobjects manifest file entry with this:

"com.unity.netcode.gameobjects": "https://github.com/Unity-Technologies/com.unity.netcode.gameobjects.git?path=com.unity.netcode.gameobjects#develop-2.0.0",

Then you should not encounter that limitation with NetworkAnimator.

Let me know if that resolves your issue?

NoelStephensUnity avatar Oct 21 '24 22:10 NoelStephensUnity

@NoelStephensUnity No more warnings appear and the animation syncs correctly. Thanks!

Royal2022 avatar Oct 21 '24 22:10 Royal2022