Nested enum shows as int in Inspector

I have the following class structures:

public class NodeOwner : ScriptableObject
{
    public Node Root = new Node();
}

[System.Serializable]
public class Node
{
   public NodeType Type = NodeType.None;
   public Node[] Children = null;
}

public enum NodeType
{
   None,
   Type1,
   Type2
}

I have an editor script to create an instance of the NodeOwner. When I select the asset, the Root node appear fine in the inspector, with its Type set to None, but when I add children, their type defaults to 0 and I cannot choose node types via the inspector.

All help appreciated. I found this post but this doesn’t seem to work for me:

Thanks
Bovine

I had a similar issue related to classes inheriting from another with an enum, showing that as integers. This is worth a bug report I’d say.

I just thrown together a test case and can’t reproduce this problem under any circumstances.

My test cases look like this:

public enum ETestEnum
{
    One, Two, Three
}

[System.Serializable]
public class DeepNested
{
    public string name;
    public ETestEnum enumVal;
}

[System.Serializable]
public class NestedClass
{
    public string name;
    public ETestEnum enumVal;
    public DeepNested child;
}

[System.Serializable]
public class DerivedClass : NestedClass
{
    public ETestEnum secondEnumVal;
}

public class TestScript : MonoBehaviour
{
    public DerivedClass[] classInst;
}

public class TestScriptable : ScriptableObject
{
    public DerivedClass[] childs;
}

I’ve actually tried every data class. I was extending the example step by step. I have even deep nested classes as well as a derived class and the enum always shows up as a drop down field:

100691-enumtestresult.png

Some further notes:

  • Keep in mind that custom serialized classes do not support polymorphism. You can use a derived class as long as its base classes and itself is serializable, but you can’t use a base class variable and store a derived class in that variable. Unity’s serialization system treats such classes like structs. They are serialized based on the variable type.
  • Custom serialized classes must not create any kind of circular reference. In the OP code the Node class has an array of Nodes. This does not work. The serialization system will throw an error in this case.
  • I strongly recommend to read the documentation on script serialization carefully. Make sure you really understand everything that is stated there. If something is not clear, feel free to ask a question. Please DO NOT post a comment or even an answer to this question.
  • If someone has an actual test case which reproduces this problem, please leave a comment. It would be great if you could tell us your operating system and unity version. My tests were carried out on Win10(64bit) and Unity 5.6.1f1 Personal. Maybe you can pack the test case into a zip file and upload it for others to test.