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
- [Discussions] "NativePassData.GraphPasses()" has GC Alloc of ~256 B when using Render Pass
- Setting Shader Graph to Surface Type "Transparency" and Render Face "Both" breaks the preview
- Warning "Unknown pseudo class "multiline"" is logged when the Animator is loaded or in use after picking Motion in a States Inspector
- Deleting the property in the Blackboard and then creating the different type property with the same name throws an error
- Selector gets stuck in UI if scroll is used while dragging
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