I've been writing a script recently for chests in my multiplayer game, and I need a way to store a list of its items that is synced between the clients. I tried using a NetworkVariable array but that didn't work for some reason. Unity says that it has a NetworkList type which seems like it should be able to accomplish my goal, but I need advice on how to structure the data I need to be sending. My current class for items looks like this
public struct ItemNetworkStruct : INetworkSerializable
{
public Item.ItemType type;
public int amount;
//Attribute values
public ItemAttribute.AttributeName[] attributeNames;
public float[] attributeValues;
public FixedString512Bytes attributeInfo;
//Spell values
public Spell.SpellType spellType;
public SpellAttribute.AttributeType[] spellAttributeTypes;
public float[] spellAttributeValues;
public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
{
serializer.SerializeValue(ref type);
serializer.SerializeValue(ref amount);
serializer.SerializeValue(ref attributeNames);
serializer.SerializeValue(ref attributeValues);
serializer.SerializeValue(ref spellType);
serializer.SerializeValue(ref spellAttributeTypes);
serializer.SerializeValue(ref spellAttributeValues);
serializer.SerializeValue(ref attributeInfo);
}
}```
This has been working so far for what I need, but the attribute and float arrays are reference types, so I can't use this struct in a NetworkList. I need some advice on how to structure this so I can store the data in an array-esque format without using reference types, if possible, so I can use it in a network list.