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

Package: Multiplayer Netcode for GameObjects

-

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)

  1. Resolution Note:

    There are no fixes planned for this Bug

  2. 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

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.