- Home /
enum in generic subclass shows as integer
I just recently discovered that using enum fields in an abstract generic class (like the good old Singleton<T>
), only show up as integer fields and not as drop down menus in derived classes.
Why is that? Is it a bug?
Answer by Bunny83 · Mar 02, 2017 at 01:15 PM
You gave not much information about your exact case. So i went ahead and created two test cases. Since only serializable classes will show up in the inspector it should be clear that the classes either are "System.Serializable" or derived from MonoBehaviour / ScriptableObject.
First i created an abstract generic base class that was derived from MonoBehaviour. The base class has a public field of an enum type. I then created an non-abstract non-generic subclass of that base class and attached it to a gameobject. The enum shows up as dropdown as expected.
For the second test i created a serializable abstract generic class that is derived from System.Object (a normal class) with the same public enum field. Then again i created a non-generic non-abstract subclass which i exposed in a seperate MonoBehaviour class as public variable. If i inspec that MonoBehaviour i see the serializable class as expandable field. The enum of that class also shows up as drop down.
Tests has been carried out in Unity 5.5.1f1
You either have a strange setup that Unity even can't serialize properly because the actual class used is either generic or abstract, you have a custom inspector / propertydrawer which messes up the display of the enum or you have set your inspector to debug mode. Which of those three reasons apply to you we can't determine by the information given in the question.
I was referring to your test case 1. I'll check which version it is on monday.
none of your exceptions apply in my case.
funny enough another enum in the derived class, created and made a field of, showed up properly.
I usually know how to create properly serialized classes and fields, which is why I'm so confused.
let's see in monday. thanks however for your thorough perimiter (if that's even English, I'm German :) )
Hmm, i've even tried enums with different underlying types (byte, uint, long) and all work the same way. I also tried enum members which do not have consecutive values (like when used as bit flags). No matter what i do the enum always shows up as expected ^^.
:) No worries, I'm german as well ^^
@Bunny83 Ok, sorry it wasn't monday. I thought I'd show a screenshot even if there's code, but you can also see the rest of the settings. Actually I don't understand the behaviour really. You can see the enum showing up with 0 at the bottom of the inspector:
Your answer
![](https://koobas.hobune.stream/wayback/20220612112307im_/https://answers.unity.com/themes/thub/images/avi.jpg)