NetworkAnimator (If there are more than 58 variables in the animator, an error)
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
- Create a project in Unity 6 preview.
- Install "Netcode for GameObjects 2.0.0" and "Multiplayer Play Mode 1.3.0" from the Package Manager.
- Create an object and attach the "Network Manager" component, select "Unity Transport" in the Network Transport.
- 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.
- Attach the created prefab to the object with the "Network Manager" component and create a script for hosting and connection.
- Then host on the first one, and connect on the second one
- 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:
Character animation when there is no error:
Screenshot of the error:
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
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
@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 No more warnings appear and the animation syncs correctly. Thanks!