Instance fields with enum types serialized with [OdinSerialize] are reverted to their default values when applied to a prefab

Issue #62 resolved
Former user created an issue

Problem: Enum instance fields serialized with [OdinSerialize] are reverted to their default values when applying a prefab instance to a prefab. This is on a class inheriting from SerializedMonoBehaviour.

Note: Please remove the previous issue "#61: Prefab serialization example throws errors" Sorry! I had forgotten to change the title to the one in this post. Love what you guys are up to! Keep it up.

Unity Version: 5.6.0f3

Comments (5)

  1. Bjarke Elias

    Can you post the code that is causing the problem? Just ran this example which seemed to work just fine.

    public class MyComponent : SerializedMonoBehaviour
    {
        [OdinSerialize]
        private MyEnum MyEnum;
    }
    
    public enum MyEnum
    {
        A,
        B,
        C
    }
    
  2. John Ploskey

    So after some investigation, I've narrowed it down to the following: The problem only seems to happen with public enum fields marked with the OdinSerialize attribute. I may have missed something and this is a part of the serialization system. Is Unity's serialization of the public field conflicting with Odin's? Replacing the public enum field with an integer works fine.

    This works...

    public enum Heat {
        Hot,
        Cold
    }
    
    public class Test : SerializedMonoBehaviour {
        [OdinSerialize] Heat heat;
    }
    

    This does not...

    public enum Heat {
        Hot,
        Cold
    }
    
    public class Test : SerializedMonoBehaviour {
        [OdinSerialize] public Heat heat;
    }
    
  3. Tor Esa Vestergaard

    Ah, I suspect I know what the issue may be. Will look into this as soon as I get a moment to do so.

  4. Log in to comment