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

Suddenly got this error when I select objects in World UI hierarchy.

Trying to read value of type Enum while reading a value of type Keyword
UnityEngine.UIElements.StyleSheet:ReadEnum(StyleValueHandle)
Unity.UI.Builder.StyleValueHandleExtensions:GetEnum(StyleSheet, StyleValueHandle) (at Library/PackageCache/com.unity.ui.builder@0.9.0-preview/Editor/Utilities/StyleSheetExtensions/StyleValueHandleExtensions.cs:144)
Unity.UI.Builder.BuilderInspectorStyleFields:RefreshStyleField(String, VisualElement) (at Library/PackageCache/com.unity.ui.builder@0.9.0-preview/Editor/Builder/Inspector/BuilderInspectorStyleFields.cs:531)
Unity.UI.Builder.BuilderInspectorLocalStyles:Refresh() (at Library/PackageCache/com.unity.ui.builder@0.9.0-preview/Editor/Builder/Inspector/BuilderInspectorLocalStyles.cs:130)
Unity.UI.Builder.BuilderInspector:RefreshUI() (at Library/PackageCache/com.unity.ui.builder@0.9.0-preview/Editor/Builder/Inspector/BuilderInspector.cs:413)
Unity.UI.Builder.BuilderInspector:SelectionChanged() (at Library/PackageCache/com.unity.ui.builder@0.9.0-preview/Editor/Builder/Inspector/BuilderInspector.cs:441)
Unity.UI.Builder.BuilderSelection:NotifyOfSelectionChange(IBuilderSelectionNotifier) (at Library/PackageCache/com.unity.ui.builder@0.9.0-preview/Editor/Builder/BuilderSelection.cs:266)
Unity.UI.Builder.BuilderSelection:Select(IBuilderSelectionNotifier, VisualElement) (at Library/PackageCache/com.unity.ui.builder@0.9.0-preview/Editor/Builder/BuilderSelection.cs:146)
Unity.UI.Builder.BuilderExplorer:ElementSelected(VisualElement) (at Library/PackageCache/com.unity.ui.builder@0.9.0-preview/Editor/Builder/Explorer/BuilderExplorer.cs:128)
Unity.UI.Builder.ElementHierarchyView:OnSelectionChange(List`1) (at Library/PackageCache/com.unity.ui.builder@0.9.0-preview/Editor/Utilities/ElementHierarchyView/ElementHierarchyView.cs:418)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

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

5271972–527907–1-MainMenuUI_DIFF.zip (4.87 KB)

1 Like

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?

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)

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.

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 .

5324469–535983–Assets.zip (523 Bytes)

@uDamian Seems related to the builder, can you take a look?

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?

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.

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.

2 Likes

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):

5619604--582727--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…

1 Like

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

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 :wink:
(and to be fair, it’s kinda working with only chaning the namespaces but those errors that feel more like warnings)

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. :slight_smile:

1 Like

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?

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.

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)

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.

2 Likes

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.

Can you show what your UXML contains?

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.

<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
    <ui:VisualElement style="translate: 0 0; rotate: 0;">
        <ui:VisualElement style="translate: -35px 0; flex-direction: row-reverse; justify-content: flex-end;">
            <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;" />
            <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;">
                <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;" />
            </ui:VisualElement>
        </ui:VisualElement>
    </ui:VisualElement>
</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)”.