Search Unity

Bug Error "Trying to read value of type Enum while reading a value of type Keyword"

Discussion in 'UI Toolkit' started by Jawsarn, Dec 11, 2019.

  1. Jawsarn

    Jawsarn

    Joined:
    Jan 12, 2017
    Posts:
    245
    Suddenly got this error when I select objects in World UI hierarchy.
    upload_2019-12-11_18-29-44.png
    Code (CSharp):
    1. Trying to read value of type Enum while reading a value of type Keyword
    2. UnityEngine.UIElements.StyleSheet:ReadEnum(StyleValueHandle)
    3. Unity.UI.Builder.StyleValueHandleExtensions:GetEnum(StyleSheet, StyleValueHandle) (at Library/PackageCache/com.unity.ui.builder@0.9.0-preview/Editor/Utilities/StyleSheetExtensions/StyleValueHandleExtensions.cs:144)
    4. Unity.UI.Builder.BuilderInspectorStyleFields:RefreshStyleField(String, VisualElement) (at Library/PackageCache/com.unity.ui.builder@0.9.0-preview/Editor/Builder/Inspector/BuilderInspectorStyleFields.cs:531)
    5. Unity.UI.Builder.BuilderInspectorLocalStyles:Refresh() (at Library/PackageCache/com.unity.ui.builder@0.9.0-preview/Editor/Builder/Inspector/BuilderInspectorLocalStyles.cs:130)
    6. Unity.UI.Builder.BuilderInspector:RefreshUI() (at Library/PackageCache/com.unity.ui.builder@0.9.0-preview/Editor/Builder/Inspector/BuilderInspector.cs:413)
    7. Unity.UI.Builder.BuilderInspector:SelectionChanged() (at Library/PackageCache/com.unity.ui.builder@0.9.0-preview/Editor/Builder/Inspector/BuilderInspector.cs:441)
    8. Unity.UI.Builder.BuilderSelection:NotifyOfSelectionChange(IBuilderSelectionNotifier) (at Library/PackageCache/com.unity.ui.builder@0.9.0-preview/Editor/Builder/BuilderSelection.cs:266)
    9. Unity.UI.Builder.BuilderSelection:Select(IBuilderSelectionNotifier, VisualElement) (at Library/PackageCache/com.unity.ui.builder@0.9.0-preview/Editor/Builder/BuilderSelection.cs:146)
    10. Unity.UI.Builder.BuilderExplorer:ElementSelected(VisualElement) (at Library/PackageCache/com.unity.ui.builder@0.9.0-preview/Editor/Builder/Explorer/BuilderExplorer.cs:128)
    11. Unity.UI.Builder.ElementHierarchyView:OnSelectionChange(List`1) (at Library/PackageCache/com.unity.ui.builder@0.9.0-preview/Editor/Utilities/ElementHierarchyView/ElementHierarchyView.cs:418)
    12. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
    13.  
    I'm not really sure what it originates from, to solve it I checked what selections in World UI that gave error to console, and removed their content. I had to redo those parts again, made some changes to it as well. The diffs are appended as well.

    (edit: Uploaded with both old and fixed version)

    (edit2)
    Nevermind the fix, it seems when I added the fixed code again it still breaks.^^

    (edit3)
    The most annoying thing about this is that the UI Builder doesn't seem to reload when you reopen it/create new and open, but you need to restart the whole Unity Project for it to properly reload.

    (edit4)
    It seems to be related to "display: none;" or/also flex

     

    Attached Files:

    Last edited: Dec 11, 2019
    Milky-Tea likes this.
  2. Milky-Tea

    Milky-Tea

    Joined:
    May 2, 2018
    Posts:
    3
    I too get this when I open my editorWindow.

    I tried to divide an concor fix the issue. When I thought I had found it, removed the issue, the next day the same error was back. So I don't really think there is anything wrong with our code? more likely something with unity's parser?
     
  3. Jawsarn

    Jawsarn

    Joined:
    Jan 12, 2017
    Posts:
    245
    Yeah, this is the problem I have with UI Builder rn, and probobly editorWindow works the same, it doesn't fully reload until you restart Unity? Or maybe it is combination to it crashing in parser first. So what you need to do after each "divide" in your divide and conquer, is to restart unity and see if it fixed it. But as I said in my edit, it seems to be fixed by not using any "display" enums. (So what I'm planning to do is to set these on start in the code instead)
     
  4. antoine-unity

    antoine-unity

    Unity Technologies

    Joined:
    Sep 10, 2015
    Posts:
    780
    Can you submit through the bug reporter? It does look like it's not related to a specific asset but we haven't seen this internally as far I know.

    I tried used the attached files but I have a bunch of files missing which prevent the import of the UXML file.
     
  5. Jawsarn

    Jawsarn

    Joined:
    Jan 12, 2017
    Posts:
    245
    Don't understand how to use FogBugz, and haven't seen it on the issuetracker yet. Any update on when the issue will be fixed? Added a zip with the simplest case, last tested in 2019.3.0f3 with version 0.10.0 .
     

    Attached Files:

  6. jonathanma_unity

    jonathanma_unity

    Unity Technologies

    Joined:
    Jan 7, 2019
    Posts:
    229
    @uDamian Seems related to the builder, can you take a look?
     
  7. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,231
    This was a bug that was fixed in the last release of the UI Builder package. Can you update to UI Builder 0.10.0-preview and let me know if the bug still persists?
     
    Last edited: Jan 23, 2020
  8. Jawsarn

    Jawsarn

    Joined:
    Jan 12, 2017
    Posts:
    245
    I can't seem to find 1.10.0-preview, you sure it's correct version? Latest I find is 0.10.0 which was released dec 13? Or do I need to add something more to manifest file?

    I tried 0.10.0 and it still gives bug.
    Create new xml, add selector, add visual element(optional?), on selector click display:none, save. Close unity, reopen project, click on selector => error.
     
  9. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,231
    Sorry. Typo on my part. Yes, I meant
    0.10.0-preview


    What do you mean by "reload" in this case?

    Ok, I'm able to reproduce this bug on my end. Will log it. Should be fixed in the next version of the UI Builder package.
     
    fherbst and Jawsarn like this.
  10. fherbst

    fherbst

    Joined:
    Jun 24, 2012
    Posts:
    802
    I'm also seeing this in Unity 2018 when trying to backport UXML files from 2019. Everything seems to work but I get those messages (all of them at once):

    upload_2020-3-23_12-56-35.png

    Is there a documentation somewhere on how types have changed between 2018 and 2019? Seems e.g. flex-grow was a float and now is an enum, or wordWrap which was a bool and now is a whiteSpace enum. My guess is that this causes the above errors..
     
  11. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,231
    FYI, this was fixed in the UI Builder 0.10.1-preview update. Please update to latest version if you still encounter this error.

    UIElements in Unity 2018 was still in experimental stage. The APIs have changed significantly. Using UXML files created in the UI Builder in Unity 2018 is not something we support. Here's a document that goes over all those changes:
    https://docs.google.com/document/d/1mdMtTQVUkzQi7UIBXf1Eg1FzP7krmLVXCt-NwXm1APQ
     
  12. fherbst

    fherbst

    Joined:
    Jun 24, 2012
    Posts:
    802
    Thank you, this is exactly what I was looking for.

    Even if Unity does not support that, clients still expect support for at least the last major LTS version ;)
    (and to be fair, it's kinda working with only chaning the namespaces but those errors that feel more like warnings)
     
  13. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,231
    The API was under the Experimental namespace which was a warning that it should not be used for production. Experimental features are not guaranteed to be supported, even as part of LTS.

    But we'll do our best to help with information and suggestions for workarounds to help you make it work for your case. Just don't expect any feature backports or even bug fixes. :)
     
    Jawsarn likes this.
  14. fherbst

    fherbst

    Joined:
    Jun 24, 2012
    Posts:
    802
    I totally understand! And that wasn't really meant as critique, only as a business reality, experimental namespace or not.
    We build great tools with the great features on 2019 - customers want them but enough of them still use 2018 LTS - we need to find ways to make that happen.

    On the note of helping with that - is there any way to debug loading an UXML that gives more info than just "Trying to read value..."? Like, can I somehow figure out which values are causing those issues, by manually stepping through it or so?
     
  15. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,231
    There is but it's only available in later versions of 2019 and will not be backported. Best I can suggest is to comment out sections of the UXML/USS until it works and then work backwards to see which tags/properties it doesn't like.
     
  16. herra_lehtiniemi

    herra_lehtiniemi

    Joined:
    Feb 12, 2017
    Posts:
    133
    I'm getting a similar error in Unity 2020.2.0b9.3373 with UI Toolkit 0.13.0-preview. I'm not using UI builder. Is it the same error, can I provide some extra information or something else?

    Trying to read value of type Color while reading a value of type Keyword
    UnityEngine.GUIUtility:processEvent (int,intptr,bool&) (at /Users/bokken/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:189)
     
  17. Tom-Atom

    Tom-Atom

    Joined:
    Jun 29, 2014
    Posts:
    153
    I have error like this too (I am on 1.0.0-preview.14):

    Trying to read value of type Dimension while reading a value of type Enum


    I found, that for some reason, UI builder saved left padding of VisualElement into .uxlml like this...

    padding-left: NaNpx;


    ...while it should be 0px.

    After deleting this directly from .uxml I got rid of errors.
     
    sionzee_ and HugoBD-Unity like this.
  18. Kerihobo

    Kerihobo

    Joined:
    Jun 26, 2013
    Posts:
    65
    In 2022 I also have:

    Trying to read value of type Dimension while reading a value of type Enum


    but unlike Tom-Atom's solution above, there are no strange things in my UXML to delete.
     
  19. martinpa_unity

    martinpa_unity

    Unity Technologies

    Joined:
    Oct 18, 2017
    Posts:
    480
    Can you show what your UXML contains?
     
  20. OBiwer

    OBiwer

    Joined:
    Aug 2, 2022
    Posts:
    61
    Same for me. UXML look fine, USS looks fine. no 'NaN's or something like this. Unity 2022.1.8f1

    the error message is crap btw. Even if you can't fix the issue, please improve the error message to show at which line and column the parsing fails. or at least which style property. I mean: if it is already expecting a color value to be read, then it should have already parsed the style name!?

    the error appears for me when playing. and the UI looks fine.

    Code (UXML):
    1. <ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
    2.     <ui:VisualElement style="translate: 0 0; rotate: 0;">
    3.         <ui:VisualElement style="translate: -35px 0; flex-direction: row-reverse; justify-content: flex-end;">
    4.             <ui:VisualElement style="border-top-left-radius: 50%; border-bottom-left-radius: 50%; border-top-right-radius: 50%; border-bottom-right-radius: 50%; background-color: rgb(255, 173, 0); width: 10px; height: 10px; justify-content: center; align-items: center; position: absolute;" />
    5.             <ui:VisualElement style="translate: 0 0; position: absolute; justify-content: flex-end; align-items: auto; rotate: 0; flex-direction: row-reverse; flex-shrink: 0; flex-grow: 0; width: 10px; height: 10px; overflow: visible;">
    6.                 <ui:Button tabindex="-1" text="this is a super long button" display-tooltip-when-elided="true" style="-unity-text-align: middle-right; position: absolute; right: 0; transform-origin: center; translate: 0 -15px;" />
    7.             </ui:VisualElement>
    8.         </ui:VisualElement>
    9.     </ui:VisualElement>
    10. </ui:UXML>
    (I use multiple UXML files and stick them together at runtime, but this is the only one that contains inline styles)

    also: the error appears not always but about 80% of the time this menu opens (and sometimes when it closes)


    edit: I've had a "background-color: none;" in my USS file, to get rid of the default Button style.
    It worked as in: there was no background. Solved it by setting it to transparent "rgba(0, 0, 0, 0)".
     
    Last edited: Oct 26, 2022
  21. okndmrl

    okndmrl

    Joined:
    May 25, 2019
    Posts:
    5
    I still have this error at the moment and it appears once I opened my uxml file on Windows. I was working on MacOS. I have at least 10 documents but only one of them gives this significant error, and can't figure out where it occurs.