Search Unity

Bug EnumField does not work for custom Enum type

Discussion in 'UIElements' started by Kichang-Kim, May 15, 2019.

  1. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    248
    Hi, I found that my own enum type does not work in EnumField in UXML.

    Here is minimul reproducible code:
    TestWindow.uxml
    Code (CSharp):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <UXML
    3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    4.     xmlns="UnityEngine.UIElements"
    5.     xmlns:uie="UnityEditor.UIElements"
    6.  
    7. xsi:noNamespaceSchemaLocation="../../UIElementsSchema/UIElements.xsd"
    8. xsi:schemaLocation="
    9.                        UnityEngine.UIElements ../../UIElementsSchema/UnityEngine.UIElements.xsd
    10.                        UnityEditor.UIElements ../../UIElementsSchema/UnityEditor.UIElements.xsd
    11.                        UnityEditor.PackageManager.UI ../../UIElementsSchema/UnityEditor.PackageManager.UI.xsd
    12. "
    13. >
    14.     <Foldout name="foldout" class="foldout">
    15.         <uie:EnumField label="BuildTarget" type="UnityEditor.BuildTarget" />
    16.         <uie:EnumField label="MyEnum" type="MyNamespace.MyEnum" />
    17.     </Foldout>
    18. </UXML>
    MyEnum.cs
    Code (CSharp):
    1. namespace MyNamespace
    2. {
    3.     public enum MyEnum
    4.     {
    5.         None = 0,
    6.         First = 1,
    7.         Second = 2,
    8.     }
    9. }
    10.  
    First EnumField for BuildTarget works correctly, but second EnumField for my own Enum types doesn't work. Is this bug? or intended behaviour?

    Thanks.
     
  2. patrickf

    patrickf

    Unity Technologies

    Joined:
    Oct 24, 2016
    Posts:
    37
    Hi! Could you try providing the assembly name, like this:

    <uie:EnumField label="MyEnum" type="MyNamespace.MyEnum, AssemblyName" />
     
  3. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    248
    Works. Thanks!