Why is Odin not serializing or showing my field or property?

All members which Odin thinks are being serialized by either Unity or Odin, will show up in the inspector, but it can sometimes be a little confusing to tell whether it is Unity or Odin serializing your fields and whether they are even being serialized at all. There are a few points to keep in mind:

  • If you are trying to show a member which Unity can't serialize then you must inherit from SerializedMonoBehaviour or one of its sister classes like SerializedScriptableObject in order to activate Odin's serialization.
  • When you inherit from those classes, you are getting a "mix" of Unity and Odin serialization. Odin will only serialize members which Unity can't serialize, like interface, dictionaries, etc. Unity will take care of the rest on its own.
  • Members serialized by Odin have different behaviour than members serialized by Unity. Odin-serialized members support polymorphism, null values, references, and so on. This translates to them also looking and acting differently in the inspector. For example, the default value of an Odin-serialized class is "null", and you will have to click the value in the inspector and actually assign a compatible instance to the field in order to edit values in the class.
  • Something being shown does not necessarily mean that it is being serialized. Adding [ShowInInspector] or adding members to groups, will cause them to be shown without also causing them to be serialized. When this happens, their values will be "reset" constantly, since they are never saved.

Here are a couple of examples that hopefully help you out.

public class UnityComponent : MonoBehaviour
{
	private string a;                              // Won't be serialized, nor will it show up in the inspector.

	[SerializeField]
	private string b;                              // Will be serialized by Unity and shown in the inspector.

	public string c;                               // Will be serialized by Unity and shown in the inspector.

	[SerializeField]                               // Won't be serialized as Unity does not know how,
	private Dictionary<string, AudioClip> d;       //  nor will it show up in the inspector.

	[OdinSerialize]                                // We are not inhereting from SerializedMonoBehaviour so this will
	private Dictionary<string, AudioClip> e;       // not be serialized either, nor will it show up in the inspector.
          
	[ShowInInspector]
	private Dictionary<string, AudioClip> f;       // This will be shown in the inspector, but will not be serialized.
}

public class OdinSerializedUnityComponent : SerializedMonoBehaviour
{
	private string a;                              // Won't be serialized, nor will it show up in the inspector.

	[SerializeField]
	private string b;                              // Will be serialized by Unity and shown in the inspector.

	[OdinSerialize]                                // Will be serialized by Odin and shown in the inspector.
	private string c;                              // But a good rule is to let Unity serialize it whenever you can.

	[SerializeField, OdinSerialize]
	private string d;                              // WARNING: This will be serialized by both Unity and Odin

	[OdinSerialize]
	public string e;                               // WARNING: This will be serialized by both Unity and Odin

	public string f;                               // Will be serialized by Unity and shown in the inspector.

	public Dictionary<string, AudioClip> g;        // Will be serialized by Odin and shown in the inspector.

	[OdinSerialize]
	private Dictionary<string, AudioClip> h;       // Will be serialized by Odin and shown in the inspector.

	[SerialzieField]
	private Dictionary<string, AudioClip> i;       // Will be serialized by Odin and shown in the inspector.
          
	[ShowInInspector]                              
	private Dictionary<string, AudioClip> j;       // This will be shown in the inspecotr, but will not be serialized.

	[OdinSerialize]
	private AudioClip k { get; set; }              // Will be serialized by Odin and shown in the inspector.

	[ShowInInspector]
	public AudioClip l { get; set; }               // This will be shown in the inspecotr, but will not be serialized.

	public AudioClip m { get; set; }               // Won't be serialized, nor will it show up in the inspector.
}

public interface ISomeInterface
{
    string SomeInterfaceProperty { get; set; }
}

public class OdinSerializedUnityComponent : SerializedMonoBehaviour, ISomeInterface
{
    [OdinSerialize]
    public virtual string VirtualProperty { get; set; }   // Wil not be shown or serialized, since it is virtual 
    
    [OdinSerialize]
    public string SomeInterfaceProperty { get; set; } // Wil not be shown or serialized, since it is virtual because of the interface
}

It is also important to note that it is only the top-level component that decides what is serialized by what. To demonstrate:

// This is the component you put on a GameObject. It is THIS component, and only this component, that decides whether or not something is serialized by Odin
public class MyMonoBehaviour : SerializedMonoBehaviour // Inheriting the component from SerializedMonoBehaviour means we use Odin's serialization
{
    public Dictionary<string, string> someDictionary; // Will be serialized by Odin

    [SerializeField]
    private SomeClass someClass1; // Will be serialized by Unity, NOT Odin. "someClass1.someString" will be serialized, but "someClass1.someDict" will NOT be serialized. Polymorphism is NOT supported. Null values are NOT supported.

    [OdinSerialize]
    private SomeClass someClass2; // Will be serialized by Odin, NOT Unity. Both "someClass2.someString" and "someClass2.someDict" will be serialized. Both polymorphism and null values are supported.
}

[Serializable]
public class SomeClass // No matter what you inherit from here, it makes no difference at all to the serialization of this class - that is decided "higher up" in the component itself
{
    public string someString;
    public Dictionary<string, string> someDict;
}

For more information on using Odin's serialization check out the Serialize Anything chapter from our manual.

Can I use Odin for its editors only, without using the serialization? Can I use Odin for its editors only, without using the serialization?
Can I use Odin to make inspectors for my own asset store plugins? Can I use Odin to make inspectors for my own asset store plugins?
Can I use Odin Inspector to create custom editor windows? Can I use Odin Inspector to create custom editor windows?
Does the serialization support Windows Store and UWP? Does the serialization support Windows Store and UWP?
How do I contact Sirenix to report bugs, suggest features, or in general? How do I contact Sirenix to report bugs, suggest features, or in general?
Does Odin support serialization of Unity object references? Does Odin support serialization of Unity object references?
Does Odin support interfaces? Does Odin support interfaces?
How can I add an image to the inspector? How can I add an image to the inspector?
Why isn’t Odin drawing the inspector for my script? Why isn’t Odin drawing the inspector for my script?
How will Odin handle existing editors? How will Odin handle existing editors?
How can I make a list show one item per page? How can I make a list show one item per page?
Does Odin support cross scene references? Does Odin support cross scene references?
Can I disable or hide an inspector property in play mode, or vice versa? Can I disable or hide an inspector property in play mode, or vice versa?
Which platforms are supported by Odin? Which platforms are supported by Odin?
How easy is Odin to uninstall? How easy is Odin to uninstall?
How will Odin affect performance in the inspector? How will Odin affect performance in the inspector?
How can I make my data in Odin Editor Windows persistent? How can I make my data in Odin Editor Windows persistent?
Unity crashed, could this have something to do with Odin? Unity crashed, could this have something to do with Odin?
How can I show static fields and properties in the inspector? How can I show static fields and properties in the inspector?
Can I use Odin's serialization without inheriting from SerializedMonoBehaviour etc.? Can I use Odin's serialization without inheriting from SerializedMonoBehaviour etc.?
How fast is Odin's Serialization system? How fast is Odin's Serialization system?
How stable/reliable is Odin's serialization system? Can I safely use it in my project? How stable/reliable is Odin's serialization system? Can I safely use it in my project?
Is it possible to customize how the dictionary drawer draw its key-type using attributes? Is it possible to customize how the dictionary drawer draw its key-type using attributes?
How can I make an attribute that lets you drag elements unto a member to set its value? How can I make an attribute that lets you drag elements unto a member to set its value?
Why are my values disappearing when I hit play? Why are my values disappearing when I hit play?
Can I write my own custom editor code using Odin? Can I write my own custom editor code using Odin?
Why is there a Serializable JSON Dictionary in my Odin Editor Window? Why is there a Serializable JSON Dictionary in my Odin Editor Window?
How can I rename a type without loosing data? How can I rename a type without loosing data?