I’m trying to setup syncable byte arrays for serialized classes of mine. I’m running into some behaviour I don’t fully understand, maybe someone can help explain?
I have an InteractableLoot script on my dropped item that stores the item, say a sword or whatever, for example. The SyncListByte which is a SyncList (why that isn’t a default SyncList type is beyond me…). If I have the SyncListByte declared on the InteractableLoot script, and as long as I keep it there everything works fine. If however I try to edit the List anywhere else, I get the error “SyncList not initialized”. For example:
public static SyncListByte ByteArrayToSyncListByte (byte[] bytes) {
SyncListByte list = new SyncListByte();
for (int i = 0; i < bytes.Length; i++) {
list.Add(bytes[i]);
}
return list;
}
I added the above to my GlobalMethods helper singleton to convert between an actual byte[ ] and a SyncListByte, but this will always error. I also had:
public class SyncListByte : SyncList<byte> {
public SyncListByte() { }
public SyncListByte (byte[] bytes) {
for (int i = 0; i < bytes.Length; i++) {
this.Add(bytes[i]);
}
}
this to populate a new SyncListByte with ease, but it throws errors as well. Only when I Add() and Clear() within the script that is declaring the variable does it work.
Note that this is all on the server.