Search Issue Tracker
Won't Fix
Won't Fix in 1.0.X
Votes
0
Found in [Package]
1.0.0-pre.6
Issue ID
NCCBUG-149
Regression
No
Recursive Nested Serialization does not work with NetworkVariables
Reproduction steps:
1. Open the attached "NonNullableError.zip" project
2. Observe the Console
Expected result: No "non-nullable" error
Actual result: "Assets/Test.cs(8,61): error CS8377: The type 'AbilityParam' must be a non-nullable value type, along with all fields at any level of nesting, in order to use it as parameter 'T' in the generic type or method 'NetworkVariable<T>'" error
Reproducible with: 1.0.0-pre.6 (2020.3.32f1, 2021.2.17f1, 2022.1.0b13, 2022.2.0a9)
Could not test with: 2019.4.37f1 (Netcode packages not supported), below 1.0.0-pre.6 (QosType and ConnectionConfig not found package script errors)
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- EditorGUILayout.PropertyField foldout icon inside Vertical Layout Group has an incorrect indent when used with OnInspectorGUI()
- [Android] [iOS] "NullReferenceException: Object reference not set to an instance of an object" throws when entering the Play Mode/opening the application
- The Player freezes on load when building Web platform
- Animator "Conditions" tab breaks when the only Parameter is deleted and another one is created
- "Shader error in 'Universal Render Pipeline/Lit': maximum ps_5_0 sampler register index (16) exceeded" error thrown after a build is completed when the "LOD Cross Fade" parameter is enabled
Resolution Note:
There are no fixes planned for this Bug
Resolution Note (1.0.X):
Hi,
As the error indicates, NetworkVariable doesn't support any items that don't fit C#'s unmanaged constraint - while the example you provided is a struct, it doesn't qualify as unmanaged because one of the fields is a C# array (AbilityTargetParam[]). Arrays in C# are managed types, and any struct that contains a managed type is also considered to be a managed type.
The good news is that there's a fairly simple fix to your error - replace your array with a NativeArray. The only downside is that you have to manage the memory yourself, so don't forget to dispose the array when you're done with it. See here for documentation: https://docs.unity3d.com/ScriptReference/Unity.Collections.NativeArray_1.html