ARTICLE AD BOX
So I have a simple struct that contains just a FixedString32Bytes and an int like so :
[System.Serializable] public struct SimpleDataStruct : INetworkSerializable, IEquatable<SimpleDataStruct> { public FixedString32Bytes id; public int amount; public bool Equals(SimpleDataStruct other) { ... The Equals logic ... } public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter { serializer.SerializeValue(ref id); serializer.SerializeValue(ref amount); } }I then have a wrapper struct that contains some more basic data, and an array of SimpleDataStruct, like so :
[System.Serializable] public struct ContainerStruct : INetworkSerializable, IEquatable<ContainerStruct> { public ulong ownerID; public SimpleDataStruct[] array; public int moreData; public bool Equals(ContainerStruct other) { ... The Equals logic ... } public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter { serializer.SerializeValue(ref ownerID); serializer.SerializeValue(ref array); serializer.SerializeValue(ref moreData); } }Finally, on my NetworkBehaviour class I have a NetworkList<ContainerStruct> because my players can have multiple ContainerStruct and I need them all to be synchronised.
public class PlayerArmyManager : NetworkBehaviour { private NetworkList<ContainerStruct> myContainers = new(new List<ContainerStruct>(), NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission.Owner); }I made sure to only use the simplest value types only in all my fields, but the problem is that SimpleDataStruct[] is a reference type and not a value type, so my NetworkList refuses to compile.
The type 'ContainerStruct' must be a non-nullable value type, along with all fields at any level of nesting, in order to be used as parameter 'T' in the generic type or method 'NetworkList<T>'In my game, the ContainerStruct represents an army, and the SimpleDataStruct represents a certain amount of units (with unit type id), but this is a simplified more generic version of my issue.
I really need each ContainerStruct to container an array (or any other form of collection) of SimpleDataStruct . I tried to look everywhere but couldn't find anyone else talking about this issue or how to fix it...
How can I change my structure in order to only have non-nullable value types and have everything synced over the network ?
(Using Unity 6 and NGO 2.9.2 by the way).
