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
- Editor crash on "PPtr<Shader>::operator Shader*() const" when checking in changes with a very long comment in Unity Version Control window
- [Ubuntu] Toolbar and menu items for Version Control lack spaces in text on Linux
- Unity Version Control window Pending Changes tab’s Item checkbox is unresponsive when clicked and the item list is empty
- Audio stuttering occurs when heavy processing is performed while OnAudioFilterRead is in use
- Inconsistent Node search results in VFX Graph
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