Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Trying to use UI Toolkit nothing shows up

Discussion in 'UI Toolkit' started by tatsuuuuuuu, Sep 8, 2020.

  1. tatsuuuuuuu

    tatsuuuuuuu

    Joined:
    May 12, 2020
    Posts:
    35
    As you can see in the UI debugger PannelSettings shows up and I find my whole UI hierarchy with my classes.

    but nothing is visible in the game view :

    Screenshot from 2020-09-08 16-12-40.png

    I get no error message in the console.

    what is missing?
     
    Last edited: Sep 9, 2020
  2. JuliaP_Unity

    JuliaP_Unity

    Unity Technologies

    Joined:
    Mar 26, 2020
    Posts:
    666
    Hello, the errors you're mentioning are related to the UI Builder and should not be interfering with your UI working in Edit mode but not in Play mode (that's what's happening, correct?).

    Can you take a look at the right side of the Debugger and check that the layout is computing to valid sizes? Also can you share your UXML contents?
     
  3. tatsuuuuuuu

    tatsuuuuuuu

    Joined:
    May 12, 2020
    Posts:
    35
    yes that's what's happening.

    ah I didn't understand there was more of the debugger. in the debugger the width and height are 0 all the way to the topmost element which is wrong it should be my viewport size correct?

    Code (CSharp):
    1. <ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
    2.     <ui:VisualElement name="MainPanel" class="panel">
    3.         <Style src="RootOfVisualTree.uss" />
    4.         <ui:Label text="How Do You Do" display-tooltip-when-elided="True" name="Howdoyoudo" />
    5.     </ui:VisualElement>
    6. </ui:UXML>
    I tried setting a fixed width and height in px, that didn't help
     
  4. tatsuuuuuuu

    tatsuuuuuuu

    Joined:
    May 12, 2020
    Posts:
    35
    I don't understand why the UI is not showing up. I have no errors, and I set a pixel width and height for the panel

    There is nothing visible when i hit run.
     
  5. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    970
    I used the UI document that you pasted above and it did show up at runtime. Is there a project you can share so that we can have a look at it?
     
  6. tatsuuuuuuu

    tatsuuuuuuu

    Joined:
    May 12, 2020
    Posts:
    35
    repo
     
    Last edited: Sep 9, 2020
  7. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    970
    The Reference DPI in your PanelSettings asset is set to 0, which will basically scale the whole panel into nothingness. To see something in your project, I reverted the reference DPI back to 96, and I added a red label in your UI builder asset.
     
    tatsuuuuuuu and NymoBasepro like this.
  8. tatsuuuuuuu

    tatsuuuuuuu

    Joined:
    May 12, 2020
    Posts:
    35
    thank you very much!!

    no idea how that got to be.

    this is as fresh as it gets as you can probably tell.

    (I think 0 is the default value)

    Do you know why this error pops in and out of existence :


    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. Unity.UI.Builder.StyleSheetExtensions.FixRuleReferences (UnityEngine.UIElements.StyleSheet styleSheet) (at Library/PackageCache/com.unity.ui.builder@1.0.0-preview.6/Editor/Utilities/StyleSheetExtensions/StyleSheetExtensions.cs:45)
    3. Unity.UI.Builder.BuilderDocumentOpenUSS.FixRuleReferences () (at Library/PackageCache/com.unity.ui.builder@1.0.0-preview.6/Editor/Builder/Document/BuilderDocumentOpenUSS.cs:69)
    4. Unity.UI.Builder.BuilderDocumentOpenUXML.OnAfterDeserialize () (at Library/PackageCache/com.unity.ui.builder@1.0.0-preview.6/Editor/Builder/Document/BuilderDocumentOpenUXML.cs:662)
    5. Unity.UI.Builder.BuilderDocument.OnAfterDeserialize () (at Library/PackageCache/com.unity.ui.builder@1.0.0-preview.6/Editor/Builder/Document/BuilderDocument.cs:392)
    ?
    and did you get it at all?
     
  9. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    970
    Yes I got it. It's an issue that was reported in the past, but we didn't have reproducible steps. Until now that is :) Thanks for sharing your project.
     
    tatsuuuuuuu likes this.
  10. tatsuuuuuuu

    tatsuuuuuuu

    Joined:
    May 12, 2020
    Posts:
    35
    no problem.

    I did delete my repo so don't get rid of the copy you cloned.
     
    mcoted3d likes this.
  11. tatsuuuuuuu

    tatsuuuuuuu

    Joined:
    May 12, 2020
    Posts:
    35

    Any idea why my USS file is not doing anything? it is recognized in ui builder but when run there is clearly no link to it
     
  12. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    970
    The USS file seems to work fine here? I tested with a label with its color set in "RootOfVisualTree.uss", it showed up in playmode.
     
    tatsuuuuuuu likes this.
  13. tatsuuuuuuu

    tatsuuuuuuu

    Joined:
    May 12, 2020
    Posts:
    35
    not for me.

    is this a linux bug? I've got absolutely no USS applying.

    this does absolutely nothing for example :

    Code (CSharp):
    1. *{
    2. color: red !important;
    3. background: red !important;
    4. }
    For now I've been using the UI in UI builder to reproduce what I want straight into the UXML (this is much slower for me and also very constraining.

    also while I have you there is no USS limit to what we can do right? this is pretty much a html 5 css 3 standart implementation, correct?

    doing this for example is entirely possible, correct? https://codepen.io/tatsujb/pen/RwNJzXY

    I made a separate thread for USS issues : https://forum.unity.com/threads/i-w...eb-but-ui-builder-is-not-playing-ball.967495/
     
    Last edited: Sep 10, 2020
  14. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    970
    Could be linux related. Filing a bug (Help > Report a Bug...) would allow us to investigate this.

    UXML+USS is not an HTML+CSS compliant implementation. It's a game UI framework that's inspired by the web standards, but diverges in some ways to make it better suited for high performance game development.

    There are features that we don't support, but may do so in the future. Filters (such as blurs, drop-shadows, etc) are not yet supported.
     
    tatsuuuuuuu likes this.
  15. tatsuuuuuuu

    tatsuuuuuuu

    Joined:
    May 12, 2020
    Posts:
    35
    What I find incomprehensible is how is unity supposed to understand that I want to use that file.

    I've specified this nowhere, contrary to the UI document file :
    Screenshot from 2020-09-10 16-38-33.png

    Now, yes the uxml and uss file do have the exact same name but to me that isn't enough for unity to be able to figure out that it's supposed to use that file.

    When you grabbed my project my .uss file already had classes, did you add yours beside those or was your uss file blank?

    how do you link a uss file to a uxml?

    I went ahead and created the issue just in case.
    could the ordering norms (https://developer.mozilla.org/en-US/docs/Web/CSS/Shorthand_properties) be respected? they exist for very good reasons.

    I hope this comes quick.

    in the past two years CSS performance has skyrocketed and now it's a force to be reckoned with.

    people get more and more creative with it and unlocking the full potential of css on unity would do unity untold levels of good.

    you say drop shadow isn't supported, what about box shadow? anyways drop shadow is a big one. I really hope it comes soon.
     
    Last edited: Sep 10, 2020
  16. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    970
    In RootOfVisualTree.uxml, there's this:

    Code (CSharp):
    1.     <ui:VisualElement class="panel">
    2.         <Style src="RootOfVisualTree.uss" />
    3.     </ui:VisualElement>
    4.  
    The link was made in UI Builder. Given this, the USS styles from RootOfVisualTree.uss should apply to anything under that VisualElement.
     
    tatsuuuuuuu likes this.
  17. tatsuuuuuuu

    tatsuuuuuuu

    Joined:
    May 12, 2020
    Posts:
    35
    Oh yeah I have that.

    So it really is a bug.
     
  18. tatsuuuuuuu

    tatsuuuuuuu

    Joined:
    May 12, 2020
    Posts:
    35
    it's weird now I get the * selector text color to apply but nothing else.

    Like it seems that Label elements are the only thing sensitive to USS visual elements ignore it completely for example.

    I can't get it to apply for old labels though, just newly created ones.

    (an annoying thing is that unity consistently empties the USS file if we edit it outside of Unity)
     
    Last edited: Sep 10, 2020
  19. tatsuuuuuuu

    tatsuuuuuuu

    Joined:
    May 12, 2020
    Posts:
    35
    I've worked out the reason for the bug:

    Any parameter set on the uxml level can no longer be superseded by uss, even if you try to clear it, in the ui setting initial value doesn't do it (a real clear button for each paramater is cruelly missing in the current UI builder), instead it writes this new value to the uxml. and the truly bizarre part is that if you manually edit the uxml file and remove all the style of that xml node;
    all of the paramaters that you once edited in the history of all time for that node remain USS-uneditable ad vitam aeternam.

    So the only way to solve this is to delete the VisualElement or whatever from the UI Builder UI and start from scratch.

    Overall this is really problematic.

    For a solution that aims to bring the power of the web to unity, it really handicaps itself by preventing the user from writing straight-up code at every turn.

    If I could edit the uxml file and uss files and actually have the results show up in unity I could fix my mess in a much much shorter time.

    where is the other place this data is being stored that's conflicting with my edits to UXML file? can I edit that too?
     
    Last edited: Sep 11, 2020
  20. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    970
    If I understand correctly, what is happening is that an inline value was set on a property, which will indeed superseed the USS stylesheet values. You can right-click the label of a property to "unset" it in UI Builder.

    UIBuilder.png
     
    tatsuuuuuuu likes this.
  21. etienne_unity

    etienne_unity

    Unity Technologies

    Joined:
    Aug 31, 2017
    Posts:
    102
    Thanks for the feedback @tatsuuuuuuu.

    Just to clarify: the UI Builder is the recommended way to author UI with UI Toolkit (UXML and USS assets). That being said, you can uninstall the package, and edit these files by hand if you prefer, just like you would edit any XML/CSS files. USS aims at being a strict subset of the evolving CSS standards. Some properties are not supported today - they may be added in the future as we improve the framework, or they may never make it if we have no way to support them while maintaining runtime performance.

    If the Builder reverts manual edits made to UXML and USS files with no explanation, please file a bug. We have a few issues around this already, and we're tackling them.
     
    tatsuuuuuuu likes this.
  22. tatsuuuuuuu

    tatsuuuuuuu

    Joined:
    May 12, 2020
    Posts:
    35
    thanks for the replies to both of you.

    I hadn't found that unset method so that's a big plus, thank you!

    And yeah I might just do it by uninstalling UI Builder and editing files by hand.

    do you happen to know of a declared feature set so that I can know other than by trial and error what is there, what isn't?

    In anycase I hope as I've said above that features like drop shadow and blur get implemented soon! :D

    thank you very much for all your hard work!
     
    Vaupell likes this.
  23. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    970
    tatsuuuuuuu likes this.
  24. etienne_unity

    etienne_unity

    Unity Technologies

    Joined:
    Aug 31, 2017
    Posts:
    102
    Hi @tatsuuuuuuu - yes, you can generate the XSD schema for UXML (Assets / Update UXML Schema). The output can then be used by most XML file editors to drive validation and auto-completion. If you're using a recent version of JetBrains Rider, the IDE already supports the UMXL and USS syntax through the Unity Support extension (bundled with the product).
     
    tatsuuuuuuu likes this.
  25. DerDicke

    DerDicke

    Joined:
    Jun 30, 2015
    Posts:
    291
  26. DerDicke

    DerDicke

    Joined:
    Jun 30, 2015
    Posts:
    291
    mcoted3d likes this.