Search Unity

Question Custom properties doesn't seems to work (2019.3, 2020.1)

Discussion in 'UI Toolkit' started by Kaiymu_, Jun 8, 2020.

  1. Kaiymu_

    Kaiymu_

    Joined:
    Jun 1, 2016
    Posts:
    47
    Hello everyone,

    I'm trying to use the custom properties like displayed here. I just copy paste the code.
    https://docs.unity3d.com/2020.1/Doc...7.1511540736.1589201301-1108364202.1557781689

    Sadly, it doesn't seems to work I always get the following error

    "Unhandled type Variable"
    Code (CSharp):
    1. Unhandled type Variable
    2.   at Unity.UI.Builder.StyleSheetToUss.ValueHandleToUssString (UnityEngine.UIElements.StyleSheet sheet, Unity.UI.Builder.UssExportOptions options, System.String propertyName, UnityEngine.UIElements.StyleValueHandle handle) [0x001b3] in T:\Program Files\Unity projects\UIElementsPrototype\UIElements_Prototype\Library\PackageCache\com.unity.ui.builder@0.11.2-preview\Editor\Utilities\StyleSheetExtensions\StyleSheetToUss.cs:121
    3.   at Unity.UI.Builder.StyleSheetToUss.ValueHandlesToUssString (System.Text.StringBuilder sb, UnityEngine.UIElements.StyleSheet sheet, Unity.UI.Builder.UssExportOptions options, System.String propertyName, UnityEngine.UIElements.StyleValueHandle[] values, System.Int32& valueIndex, System.Int32 valueCount) [0x00090] in T:\Program Files\Unity projects\UIElementsPrototype\UIElements_Prototype\Library\PackageCache\com.unity.ui.builder@0.11.2-preview\Editor\Utilities\StyleSheetExtensions\StyleSheetToUss.cs:149
    4.   at Unity.UI.Builder.StyleSheetToUss.ValueHandlesToUssString (System.Text.StringBuilder sb, UnityEngine.UIElements.StyleSheet sheet, Unity.UI.Builder.UssExportOptions options, System.String propertyName, UnityEngine.UIElements.StyleValueHandle[] values, System.Int32& valueIndex, System.Int32 valueCount) [0x00064] in T:\Program Files\Unity projects\UIElementsPrototype\UIElements_Prototype\Library\PackageCache\com.unity.ui.builder@0.11.2-preview\Editor\Utilities\StyleSheetExtensions\StyleSheetToUss.cs:140
    5.   at Unity.UI.Builder.StyleSheetToUss.ToUssString (UnityEngine.UIElements.StyleSheet sheet, Unity.UI.Builder.UssExportOptions options, UnityEngine.UIElements.StyleRule rule, System.Text.StringBuilder sb) [0x00114] in T:\Program Files\Unity projects\UIElementsPrototype\UIElements_Prototype\Library\PackageCache\com.unity.ui.builder@0.11.2-preview\Editor\Utilities\StyleSheetExtensions\StyleSheetToUss.cs:213
    6.   at Unity.UI.Builder.StyleSheetToUss.ToUssString (UnityEngine.UIElements.StyleSheet sheet, Unity.UI.Builder.UssExportOptions options, UnityEngine.UIElements.StyleComplexSelector complexSelector, System.Text.StringBuilder sb) [0x00046] in T:\Program Files\Unity projects\UIElementsPrototype\UIElements_Prototype\Library\PackageCache\com.unity.ui.builder@0.11.2-preview\Editor\Utilities\StyleSheetExtensions\StyleSheetToUss.cs:281
    7.   at Unity.UI.Builder.StyleSheetToUss.ToUssString (UnityEngine.UIElements.StyleSheet sheet, Unity.UI.Builder.UssExportOptions options) [0x00082] in T:\Program Files\Unity projects\UIElementsPrototype\UIElements_Prototype\Library\PackageCache\com.unity.ui.builder@0.11.2-preview\Editor\Utilities\StyleSheetExtensions\StyleSheetToUss.cs:305
    8.   at Unity.UI.Builder.StyleSheetExtensions.GenerateUSS (UnityEngine.UIElements.StyleSheet styleSheet) [0x00004] in T:\Program Files\Unity projects\UIElementsPrototype\UIElements_Prototype\Library\PackageCache\com.unity.ui.builder@0.11.2-preview\Editor\Utilities\StyleSheetExtensions\StyleSheetExtensions.cs:58
    9. UnityEngine.Debug:LogError(Object)
    10. Unity.UI.Builder.StyleSheetExtensions:GenerateUSS(StyleSheet) (at Library/PackageCache/com.unity.ui.builder@0.11.2-preview/Editor/Utilities/StyleSheetExtensions/StyleSheetExtensions.cs:74)
    11. Unity.UI.Builder.BuilderUssPreview:RefreshUSS() (at Library/PackageCache/com.unity.ui.builder@0.11.2-preview/Editor/Builder/Previews/BuilderUssPreview.cs:37)
    12. Unity.UI.Builder.BuilderUssPreview:SelectionChanged() (at Library/PackageCache/com.unity.ui.builder@0.11.2-preview/Editor/Builder/Previews/BuilderUssPreview.cs:54)
    13. Unity.UI.Builder.BuilderSelection:NotifyOfSelectionChange(IBuilderSelectionNotifier) (at Library/PackageCache/com.unity.ui.builder@0.11.2-preview/Editor/Builder/BuilderSelection.cs:274)
    14. Unity.UI.Builder.BuilderSelection:ClearSelection(IBuilderSelectionNotifier, Boolean) (at Library/PackageCache/com.unity.ui.builder@0.11.2-preview/Editor/Builder/BuilderSelection.cs:186)
    15. Unity.UI.Builder.BuilderToolbar:LoadDocumentInternal(VisualTreeAsset) (at Library/PackageCache/com.unity.ui.builder@0.11.2-preview/Editor/Builder/Toolbar/BuilderToolbar.cs:254)
    16. Unity.UI.Builder.BuilderToolbar:LoadDocument(VisualTreeAsset, Boolean) (at Library/PackageCache/com.unity.ui.builder@0.11.2-preview/Editor/Builder/Toolbar/BuilderToolbar.cs:247)
    17. Unity.UI.Builder.BuilderDocumentOpenUXML:OnPostProcessAsset(String) (at Library/PackageCache/com.unity.ui.builder@0.11.2-preview/Editor/Builder/Document/BuilderDocumentOpenUXML.cs:541)
    18. Unity.UI.Builder.BuilderDocument:OnPostProcessAsset(String) (at Library/PackageCache/com.unity.ui.builder@0.11.2-preview/Editor/Builder/Document/BuilderDocument.cs:286)
    19. Unity.UI.Builder.BuilderAssetPostprocessor:OnPostprocessAllAssets(String[], String[], String[], String[]) (at Library/PackageCache/com.unity.ui.builder@0.11.2-preview/Editor/Builder/Utilities/BuilderAssetPostprocessor.cs:42)
    20. UnityEditor.AssetPostprocessingInternal:PostprocessAllAssets(String[], String[], String[], String[], String[])
    Do any of you have any idea on what's going on?

    Thanks you.
     
  2. sebastiend-unity

    sebastiend-unity

    Unity Technologies

    Joined:
    Nov 9, 2015
    Posts:
    184
    Hi Kaiymu_,

    Which version of the editor & which version of the UI Builder package are you using? Feels like missing var() support on the builder side, possibly due to an older version of the builder package.
     
  3. Kaiymu_

    Kaiymu_

    Joined:
    Jun 1, 2016
    Posts:
    47
    Hello!

    Yes sorry I should have linked that before.

    I've tried with
    2019.3.6
    2019.3.15
    2020.1.0b11

    And UIBuilder version
    0.11.2
    UIElements Runtime
    0.0.4
    UIElements
    1.0.0

    Thank you for your help!
     
  4. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,231
    UI Builder does not yet support `var()` in USS. So if you USS contains any use of USS Variables, you cannot use it with the UI Builder. We should have support for `var()` in the next release of the UI Builder package.
     
    StephanieRowlinson likes this.
  5. Kaiymu_

    Kaiymu_

    Joined:
    Jun 1, 2016
    Posts:
    47
    Okay!
    Thank you Damian for your answer, I'll test that as soon as the update is out!
     
  6. Kaiymu_

    Kaiymu_

    Joined:
    Jun 1, 2016
    Posts:
    47
    Hello again,

    Thank you for the update (I'm using UIBuilder 1.0.0 with 2019.3.15).
    It's really fun to play with var()
    Just a question, it seems to be only working with the current .class you're using.

    Code (CSharp):
    1. :root {
    2.     --color3: rgb(255, 0, 0);
    3. }
    4.  
    5. .element {
    6.     --color1: rgb(255, 0, 0);
    7.     background-color: var(--color1);
    8. }
    If I do
    Code (CSharp):
    1.     background-color: var(--color3);
    It doesn't works.

    Is there any way to get a var() from an other class?
    Also, is there ways to create var() from UIBuilder or we have to open the uss?

    This update is really useful to thank you for that!
     
    Whitebrim likes this.
  7. Kaiymu_

    Kaiymu_

    Joined:
    Jun 1, 2016
    Posts:
    47
    Hello guys.

    Any update on that topic?
    Thanks!
     
  8. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,231
    :root is a bit special and might not be handled properly by the UI Builder. But you should be able to use variables from any other class as long as that class and the one that uses the variable, both match the element you're inspecting. When inspecting selectors, you will always see the value of variables defined within the current selector, as selectors don't know about each other. They only come together when used in a VisualElement tree.

    This is not yet supported. It's planned as a future feature.
     
  9. Kaiymu_

    Kaiymu_

    Joined:
    Jun 1, 2016
    Posts:
    47
    Hello Damian,

    Thanks you for your answer!

    Do you have an exemple of what you're saying? I'm not sure I understand perfectly.
    Basically on the exemple below, the color matchs both background-color so it should work. Instead it's displaying a plain black color.

    They only come together when used in a VisualElement tree.
    Does that mean that I it would work in runtime but not in UIbuilder view?
    I tested that also, sadly didn't worked!
     
  10. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,231
    Some example code can be found here:
    https://docs.unity3d.com/2020.1/Documentation/Manual/UIE-USS-CustomProperties.html

    As for what I meant by:
    They only come together when used in a VisualElement tree.

    was that you cannot see what values variables are on individual selectors in USS as you inspect them in the UI Builder. You can only see the values being applied when inspecting actual VisualElements in the Canvas or where you've instantiated your UI. But otherwise, your UI in UI Builder should definitely look the same as it does at runtime, If that's not the case, we can see what options need to be tweaked or if it's a bug.