#Why automatic serializers not work with [SerializeField]

6 messages · Page 1 of 1 (latest)

brazen bobcat
#

My english not good, so I show you code.
For example:

    // It's work
    [SyncVar(ReadPermissions = ReadPermission.OwnerOnly)]
    private CustomStruct customStruct;

    [Serializable]
    public struct CustomStruct
    {
        // Clients can receive value.
        public int value;
    }
    // It's not work
    [SyncVar(ReadPermissions = ReadPermission.OwnerOnly)]
    private CustomStruct customStruct;

    [Serializable]
    public struct CustomStruct
    {
        // Clients cannot receive value. Why is that?
        // only public field works?
        [SerializeField]
        private int value;        
    }
silver cairn
#

It's because the field is private so the value cannot be re-assigned. They are also intentionally ignored because it's assumed user doesn't want private serialized. BUT I could have sworn it was supposed to modify them when adding the serializable attribute so this might be a oversight. I'll check into it and let you know. Ty

silver cairn
#

privates arent included because they would need to be made public. this is doable if the processor generates for that class in the same module thats being codegenerated, but not otherwise.

#

which is 100% a race condition and not something I can get around because of how unity works. so youd just have to make them public.