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

Question Unexpected behavior with playmode vs ui builder

Discussion in 'UI Toolkit' started by AgelessFrost, Sep 19, 2022.

  1. AgelessFrost

    AgelessFrost

    Joined:
    Jan 26, 2019
    Posts:
    5
    Unity Version 2021.3.9f1

    I'm having some trouble with the UI Builder Preview not matching what is displayed in game. For example I have it looking like this in the builder

    and yet when I enter play mode it looks like this and is always visible even when the window is not supposed to be visible

    I have no scripts trying to do any logic with these, and other parts of this ui are working as expected. They were previously displaying but when I attempted to do these through the USS they began displaying these white circles in playmode. Is there something wrong with how I have this set up? It's not exactly clear to me in any guides or information. In the builder it works great so I just don't understand. Anyone have any insight?
    each of these circles is a xml template that uses those ```#need-item-energy .need-border``` to personalize them, but the shape and sizing comes from the simple .need-item at the bottom there

    Here are all my relevant uss and uxml files

    This is the base need item uss
    Code (CSharp):
    1. .need-item {
    2.     flex-basis: 32px;
    3.     height: 100%;
    4.     flex-shrink: 0;
    5.     background-image: url('project://database/Assets/Metaterra/Sprites/UI/SimUI-needs-border.png?fileID=2800000&guid=678657a37f6911c488b2d28f274828e5&type=3#SimUI-needs-border');
    6.     border-top-left-radius: 32px;
    7.     border-bottom-left-radius: 32px;
    8.     border-top-right-radius: 32px;
    9.     border-bottom-right-radius: 32px;
    10.     -unity-background-scale-mode: scale-and-crop;
    11.     justify-content: center;
    12.     align-items: center;
    13.     width: 32px;
    14.     margin-left: 1.5px;
    15.     margin-right: 1.5px;
    16.     overflow: hidden;
    17.     margin-top: 1.5px;
    18.     margin-bottom: 1.5px;
    19.     -unity-background-image-tint-color: rgba(255, 255, 255, 255);
    20. }
    21.  
    22. .need-item-background {
    23.     background-image: url('project://database/Assets/Metaterra/Sprites/UI/SimUI-needs-background.png?fileID=2800000&guid=c54cce99c05b935419b991a52e03afb7&type=3#SimUI-needs-background');
    24.     width: 100%;
    25.     height: 100%;
    26.     display: flex;
    27.     -unity-background-image-tint-color: rgb(255, 255, 255);
    28.     align-items: center;
    29.     justify-content: center;
    30.     -unity-background-scale-mode: stretch-to-fill;
    31.     overflow: hidden;
    32.     border-top-left-radius: 32px;
    33.     border-bottom-left-radius: 32px;
    34.     border-top-right-radius: 32px;
    35.     border-bottom-right-radius: 32px;
    36.     position: absolute;
    37. }
    38.  
    39. .need-level-overlay {
    40.     background-image: url('project://database/Assets/Metaterra/Sprites/UI/SimUI-needs-level-wave.png?fileID=2800000&guid=fe21a13cc70a9e9448ebd3e2cd195a33&type=3#SimUI-needs-level-wave');
    41.     width: 29px;
    42.     height: 110%;
    43.     display: flex;
    44.     -unity-background-image-tint-color: rgb(99, 99, 99);
    45.     align-items: center;
    46.     justify-content: center;
    47.     -unity-background-scale-mode: stretch-to-fill;
    48.     overflow: hidden;
    49.     border-top-left-radius: 0;
    50.     border-bottom-left-radius: 0;
    51.     border-top-right-radius: 0;
    52.     border-bottom-right-radius: 0;
    53.     top: -75%;
    54.     position: absolute;
    55.     left: 2px;
    56.     -unity-slice-top: 0;
    57.     -unity-slice-left: 0;
    58.     -unity-slice-right: 0;
    59.     -unity-slice-bottom: 0;
    60.     flex-basis: auto;
    61.     flex-direction: column;
    62.     visibility: visible;
    63.     opacity: 1;
    64. }
    65.  
    66. .need-border {
    67.     flex-basis: 32px;
    68.     height: 100%;
    69.     flex-shrink: 0;
    70.     border-left-width: 1.75px;
    71.     border-right-width: 1.75px;
    72.     border-top-width: 1.75px;
    73.     border-bottom-width: 1.75px;
    74.     border-left-color: rgb(255, 255, 255);
    75.     border-right-color: rgb(255, 255, 255);
    76.     border-top-color: rgb(255, 255, 255);
    77.     border-bottom-color: rgb(255, 255, 255);
    78.     border-top-left-radius: 32px;
    79.     border-bottom-left-radius: 32px;
    80.     border-top-right-radius: 32px;
    81.     border-bottom-right-radius: 32px;
    82.     -unity-background-scale-mode: scale-and-crop;
    83.     justify-content: center;
    84.     align-items: center;
    85.     width: 32px;
    86.     margin-left: 1.5px;
    87.     margin-right: 1.5px;
    88.     position: absolute;
    89.     top: 0;
    90.     display: flex;
    91. }
    92.  
    93. .need-icon {
    94.     width: 55%;
    95.     height: 55%;
    96.     display: flex;
    97.     -unity-background-image-tint-color: rgba(255, 255, 255, 255);
    98. }
    This is the next level up the needs container
    Code (CSharp):
    1. #need-item-energy .need-border {
    2.     border-left-color: rgb(142, 230, 255);
    3.     border-right-color: rgb(142, 230, 255);
    4.     border-top-color: rgb(142, 230, 255);
    5.     border-bottom-color: rgb(142, 230, 255);
    6. }
    7.  
    8. #need-item-energy .need-item-background {
    9.     -unity-background-image-tint-color: rgb(4, 243, 255);
    10. }
    11.  
    12. #need-item-hunger .need-icon {
    13.     background-image: url('project://database/Assets/Metaterra/Sprites/UI/SimUI-needs-icon-hunger.png?fileID=2800000&guid=2bdf9c23d11042945821815cee7c0d12&type=3#SimUI-needs-icon-hunger');
    14. }
    15.  
    16. #need-item-hunger .need-border {
    17.     border-left-color: rgb(250, 185, 126);
    18.     border-right-color: rgb(250, 185, 126);
    19.     border-top-color: rgb(250, 185, 126);
    20.     border-bottom-color: rgb(250, 185, 126);
    21. }
    22.  
    23. #need-item-hunger .need-item-background {
    24.     -unity-background-image-tint-color: rgb(255, 160, 76);
    25. }
    26.  
    27. #need-item-mental .need-icon {
    28.     background-image: url('project://database/Assets/Metaterra/Sprites/UI/SimUI-needs-icon-mental.png?fileID=2800000&guid=ee74a121492dd75458246e5c2805551a&type=3#SimUI-needs-icon-mental');
    29. }
    30.  
    31. #need-item-mental .need-border {
    32.     border-left-color: rgb(228, 228, 228);
    33.     border-right-color: rgb(228, 228, 228);
    34.     border-top-color: rgb(228, 228, 228);
    35.     border-bottom-color: rgb(228, 228, 228);
    36. }
    37.  
    38. #need-item-mental .need-item-background {
    39.     -unity-background-image-tint-color: rgb(229, 229, 229);
    40. }
    41.  
    42. #need-item-social .need-icon {
    43.     background-image: url('project://database/Assets/Metaterra/Sprites/UI/SimUI-needs-icon-social.png?fileID=2800000&guid=3527346b94870d347b40ed92f3dc0a49&type=3#SimUI-needs-icon-social');
    44. }
    45.  
    46. #need-item-social .need-border {
    47.     border-left-color: rgb(138, 236, 186);
    48.     border-right-color: rgb(138, 236, 186);
    49.     border-top-color: rgb(138, 236, 186);
    50.     border-bottom-color: rgb(138, 236, 186);
    51. }
    52.  
    53. #need-item-social .need-item-background {
    54.     -unity-background-image-tint-color: rgb(71, 238, 161);
    55. }
    56.  
    57. #need-item-fun .need-icon {
    58.     background-image: url('project://database/Assets/Metaterra/Sprites/UI/SimUI-needs-icon-fun.png?fileID=2800000&guid=5596b07a10e2da34e832db80f9c33d7b&type=3#SimUI-needs-icon-fun');
    59. }
    60.  
    61. #need-item-fun .need-border {
    62.     border-left-color: rgb(228, 214, 132);
    63.     border-right-color: rgb(228, 214, 132);
    64.     border-top-color: rgb(228, 214, 132);
    65.     border-bottom-color: rgb(228, 214, 132);
    66. }
    67.  
    68. #need-item-fun .need-item-background {
    69.     -unity-background-image-tint-color: rgb(255, 229, 0);
    70. }
    71.  
    72. #need-item-energy .need-icon {
    73.     background-image: url('project://database/Assets/Metaterra/Sprites/UI/SimUI-needs-icon-energy.png?fileID=2800000&guid=76617e98810b65c49aa7e78d23554766&type=3#SimUI-needs-icon-energy');
    74. }
    75.  
    This is the XML for the base need item
    Code (CSharp):
    1. <ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
    2.     <Style src="project://database/Assets/Metaterra/Visuals/UIToolkit/need-items.uss?fileID=7433441132597879392&amp;guid=2dc200358b728a14db0edb38f2efc156&amp;type=3#need-items" />
    3.     <ui:VisualElement name="need-item" class="need-item">
    4.         <ui:VisualElement name="need-item-background" class="need-item-background" />
    5.         <ui:VisualElement name="need-level-overlay" class="need-level-overlay" />
    6.         <ui:VisualElement name="need-border" class="need-border" />
    7.         <ui:VisualElement name="need-icon" class="need-icon" />
    8.     </ui:VisualElement>
    9. </ui:UXML>
    10.  
    This is UXML for the next level up
    Code (CSharp):
    1. <ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
    2.     <ui:Template name="NeedItem" src="project://database/Assets/Metaterra/Visuals/UIToolkit/NeedItem.uxml?fileID=9197481963319205126&amp;guid=a1bd9ce27ef34664981080706e2d5b0b&amp;type=3#NeedItem" />
    3.     <Style src="project://database/Assets/Metaterra/Visuals/UIToolkit/need-items-base-commodities.uss?fileID=7433441132597879392&amp;guid=3bd40dd15fd9e314fa5bea260c66db44&amp;type=3#need-items-base-commodities" />
    4.     <ui:VisualElement name="needs-container" style="flex-basis: 32px; top: -42px; flex-shrink: 0; position: absolute; left: 156px; justify-content: flex-start; align-items: center; width: 184px; flex-direction: row; flex-grow: 0; bottom: 93px;">
    5.         <ui:Instance template="NeedItem" name="need-item-energy" style="display: flex;">
    6.             <AttributeOverrides element-name="NeedBackground" focusable="true" />
    7.         </ui:Instance>
    8.         <ui:Instance template="NeedItem" name="need-item-hunger" style="display: flex;">
    9.             <AttributeOverrides element-name="NeedBackground" focusable="true" />
    10.         </ui:Instance>
    11.         <ui:Instance template="NeedItem" name="need-item-mental" style="display: flex;">
    12.             <AttributeOverrides element-name="NeedBackground" focusable="true" />
    13.         </ui:Instance>
    14.         <ui:Instance template="NeedItem" name="need-item-social" style="display: flex;">
    15.             <AttributeOverrides element-name="NeedBackground" focusable="true" />
    16.         </ui:Instance>
    17.         <ui:Instance template="NeedItem" name="need-item-fun" style="display: flex;">
    18.             <AttributeOverrides element-name="NeedBackground" focusable="true" />
    19.         </ui:Instance>
    20.     </ui:VisualElement>
    21. </ui:UXML>
    22.  
    The UXML for the parent of that
    Code (CSharp):
    1. <ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
    2.     <ui:Template name="NeedsContainer" src="project://database/Assets/Metaterra/Visuals/UIToolkit/NeedsContainer.uxml?fileID=9197481963319205126&amp;guid=494c2d05d8e192e48a4d3524d0d8e94f&amp;type=3#NeedsContainer" />
    3.     <Style src="project://database/Assets/Metaterra/Visuals/UIToolkit/StyleSheet_Simulation_Base.uss?fileID=7433441132597879392&amp;guid=801b064fbd62a8f4280dd91695e51cad&amp;type=3#StyleSheet_Simulation_Base" />
    4.     <ui:VisualElement name="CharacterBase" style="width: 431px; height: 100%; align-items: flex-end; flex-shrink: 1;">
    5.         <ui:VisualElement name="CharacterBackground" style="width: 100%; height: 100%; background-image: url(&apos;project://database/Assets/Metaterra/Sprites/UI/ActionBarHead.png?fileID=21300000&amp;guid=715ccd7aade250f47b199c5af08d6f86&amp;type=3#ActionBarHead&apos;); -unity-background-scale-mode: stretch-to-fill; -unity-slice-left: 0; -unity-slice-top: 0; -unity-slice-right: 0; transform-origin: left bottom; justify-content: center; align-items: flex-end; border-left-width: 0; margin-left: 0;">
    6.             <ui:VisualElement name="DecorativeCenter" style="width: 397px; height: 83px; background-image: url(&apos;project://database/Assets/Metaterra/Sprites/UI/SimUI-ActionBar-FieldBackground-A.png?fileID=2800000&amp;guid=c60b4d72aef38c342aecfe1c766ce463&amp;type=3#SimUI-ActionBar-FieldBackground-A&apos;); -unity-background-scale-mode: stretch-to-fill; align-items: center; margin-right: 25px; flex-direction: row; margin-top: 10px;">
    7.                 <ui:VisualElement name="SelectedCharacterDetails" style="align-items: flex-start; width: 100%; height: 100%; -unity-text-align: upper-left; justify-content: flex-start; margin-top: 0; flex-grow: 0; flex-shrink: 0.89; padding-top: 3px; padding-left: 25px;">
    8.                     <ui:VisualElement name="CharacterPortraitTrait" style="flex-basis: 0; top: -160px; height: 150px; flex-shrink: 0; position: absolute; left: 0; background-image: url(&apos;project://database/Assets/Plugins/SimpleFileBrowser/Sprites/SimpleFileBrowserSlicedBackground2.psd?fileID=2800000&amp;guid=6ff773ea42aedd04c8bb96a1fe9a73b8&amp;type=3#SimpleFileBrowserSlicedBackground2&apos;); -unity-slice-left: 0; -unity-slice-top: 0; -unity-slice-right: 0; -unity-slice-bottom: 0; border-left-width: 0; border-right-width: 0; border-top-width: 0; border-bottom-width: 0; border-left-color: rgb(248, 51, 51); border-right-color: rgb(248, 51, 51); border-top-color: rgb(248, 51, 51); border-bottom-color: rgb(248, 51, 51); border-top-left-radius: 100px; border-bottom-left-radius: 100px; border-top-right-radius: 100px; border-bottom-right-radius: 100px; -unity-background-scale-mode: stretch-to-fill; justify-content: center; align-items: center; width: 150px;">
    9.                         <ui:Button display-tooltip-when-elided="true" name="CharacterPortrait" style="left: 0; top: 0; flex-basis: auto; width: 90%; height: 90%; border-top-left-radius: 100px; border-bottom-left-radius: 100px; border-top-right-radius: 100px; border-bottom-right-radius: 100px; background-image: resource(&apos;NFTIcons/noun_1&apos;); overflow: visible;" />
    10.                     </ui:VisualElement>
    11.                     <ui:Label text="Maximilianus" display-tooltip-when-elided="true" name="CharacterName" style="background-image: none; font-size: 24px; -unity-text-align: middle-left; border-bottom-width: 0; padding-bottom: 0; margin-top: 7px; -unity-font-style: bold; margin-left: 0; margin-right: 2px; margin-bottom: 1px; padding-left: 0; padding-right: 0; padding-top: 0; white-space: nowrap; color: rgb(255, 255, 255); align-items: flex-start;" />
    12.                     <ui:Label text="is going to class" display-tooltip-when-elided="true" name="CharacterCurrentAction" style="background-image: url(&apos;project://database/Assets/Plugins/SimpleFileBrowser/Sprites/SimpleFileBrowserSlicedBackground2.psd?fileID=2800000&amp;guid=6ff773ea42aedd04c8bb96a1fe9a73b8&amp;type=3#SimpleFileBrowserSlicedBackground2&apos;); font-size: 14px; max-width: 100%; white-space: normal; color: rgb(166, 166, 87); -unity-background-image-tint-color: rgb(55, 56, 47); -unity-slice-left: 0; -unity-slice-top: 0; -unity-slice-right: 0; -unity-slice-bottom: 0; -unity-background-scale-mode: stretch-to-fill; border-top-left-radius: 5px; border-bottom-left-radius: 5px; border-top-right-radius: 5px; border-bottom-right-radius: 5px; -unity-text-align: middle-center; height: auto; padding-left: 5px; padding-right: 5px; justify-content: center; align-items: center; margin-left: 0; margin-right: 15px; padding-top: 2px; padding-bottom: 2px;" />
    13.                     <ui:Instance template="NeedsContainer" name="NeedsContainer" style="position: absolute; top: 16px; opacity: 1;" />
    14.                 </ui:VisualElement>
    15.                 <ui:VisualElement name="Divider" style="position: relative; width: 7px; height: 55%; justify-content: flex-start; background-color: rgb(78, 80, 87);" />
    16.                 <ui:VisualElement name="CurrencyDetails" style="align-items: center; width: 100%; height: 100%; justify-content: center;">
    17.                     <ui:Label text="$20.289" display-tooltip-when-elided="true" name="CharacterCurrency" style="font-size: 27px; -unity-font-style: bold; margin-left: -28px; padding-right: 0; padding-left: 0; color: rgb(255, 255, 255);" />
    18.                 </ui:VisualElement>
    19.             </ui:VisualElement>
    20.         </ui:VisualElement>
    21.     </ui:VisualElement>
    22. </ui:UXML>
    23.  
    Then the final parent
    Code (CSharp):
    1. <ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
    2.     <ui:Template name="HeroFooter" src="project://database/Assets/Metaterra/Visuals/UIToolkit/HeroFooter.uxml?fileID=9197481963319205126&amp;guid=28aa7e5b75d47d741aea6cf281a465bb&amp;type=3#HeroFooter" />
    3.     <Style src="project://database/Assets/Metaterra/Visuals/UIToolkit/StyleSheet_Simulation_Base.uss?fileID=7433441132597879392&amp;guid=801b064fbd62a8f4280dd91695e51cad&amp;type=3#StyleSheet_Simulation_Base" />
    4.     <ui:VisualElement name="Screen" picking-mode="Ignore" class="footer">
    5.         <ui:VisualElement name="Bottom" picking-mode="Ignore" style="width: 100%; height: 100%; justify-content: flex-end; background-color: rgba(0, 0, 0, 0);">
    6.             <ui:VisualElement name="Core" picking-mode="Ignore" style="height: 132px; flex-direction: row; justify-content: space-between; display: flex; opacity: 1; visibility: visible; background-color: rgba(0, 0, 0, 0);">
    7.                 <ui:Instance template="HeroFooter" name="HeroFooter" />
    8.                 <ui:VisualElement name="TimeBase" style="width: 501px; height: 100%;">
    9.                     <ui:VisualElement name="TimeBackground" style="width: 100%; height: 100%; background-image: url(&apos;project://database/Assets/Metaterra/Sprites/UI/ActionBarTail.png?fileID=21300000&amp;guid=f332d680042c8fb40aa2a88ccaace9a1&amp;type=3#ActionBarTail&apos;); -unity-background-scale-mode: stretch-to-fill; -unity-slice-left: 0; -unity-slice-top: 0; -unity-slice-right: 0; transform-origin: right; justify-content: center; align-items: flex-start; border-left-width: 0; margin-left: 0;">
    10.                         <ui:VisualElement name="DecorativeCenter" style="width: 451px; height: 83px; background-image: url(&apos;project://database/Assets/Metaterra/Sprites/UI/SimUI-ActionBar-FieldBackground-C.png?fileID=2800000&amp;guid=ebb125ee0e377c8428b52ad309b65f74&amp;type=3#SimUI-ActionBar-FieldBackground-C&apos;); -unity-background-scale-mode: stretch-to-fill; align-items: center; margin-right: 0; margin-left: 44px; margin-top: 12px; -unity-slice-left: 0; flex-direction: row; justify-content: center; padding-top: 5px;">
    11.                             <ui:VisualElement name="SimulationTimeDetails" style="align-items: flex-start; width: 100%; height: 100%; -unity-text-align: upper-left; justify-content: flex-start; margin-top: 0; flex-grow: 0; flex-shrink: 0.75; padding-left: 48px; font-size: 12px;">
    12.                                 <ui:Label text="Wednesday, 09:50 PM" display-tooltip-when-elided="true" name="DayTime" style="background-image: none; font-size: 20px; -unity-text-align: upper-center; border-bottom-width: 0; padding-bottom: 0; margin-top: 7px; -unity-font-style: bold; margin-bottom: 2px; margin-right: 2px; margin-left: 1px; padding-right: 0; padding-left: 0; color: rgb(255, 255, 255);" />
    13.                                 <ui:Label text="September 31, 2022" display-tooltip-when-elided="true" name="Date" style="background-image: url(&apos;project://database/Assets/Plugins/SimpleFileBrowser/Sprites/SimpleFileBrowserSlicedBackground2.psd?fileID=2800000&amp;guid=6ff773ea42aedd04c8bb96a1fe9a73b8&amp;type=3#SimpleFileBrowserSlicedBackground2&apos;); font-size: 13px; max-width: 90%; white-space: normal; color: rgb(54, 154, 22); -unity-background-image-tint-color: rgb(37, 54, 36); -unity-slice-left: 0; -unity-slice-top: 0; -unity-slice-right: 0; -unity-slice-bottom: 0; -unity-background-scale-mode: stretch-to-fill; border-top-left-radius: 3px; border-bottom-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; -unity-text-align: middle-center; height: auto; padding-left: 5px; padding-right: 5px; border-left-width: 0; padding-top: 2px; padding-bottom: 2px; margin-left: 2px;" />
    14.                             </ui:VisualElement>
    15.                             <ui:VisualElement name="Divider" style="position: relative; width: 7px; height: 55%; justify-content: flex-start; background-color: rgb(78, 80, 87);" />
    16.                             <ui:VisualElement name="PauseButtonArea" style="align-items: center; width: 56%; height: 100%; justify-content: center;">
    17.                                 <ui:Label display-tooltip-when-elided="true" style="font-size: 30px; -unity-font-style: bold;" />
    18.                             </ui:VisualElement>
    19.                         </ui:VisualElement>
    20.                     </ui:VisualElement>
    21.                 </ui:VisualElement>
    22.             </ui:VisualElement>
    23.         </ui:VisualElement>
    24.     </ui:VisualElement>
    25. </ui:UXML>
    26.  
    The only other item is the base style sheet I have on which is

    .footer {
    width: 100%;
    height: 100%;
    justify-content: flex-start;
    opacity: 1;
    }


    literally just that.

    I have tried a bunch of different things to debug this.
    I've tried pulling everything out of any templates and having it just work through the root. I've tried not using as many overrides, tried merging all the USS into one, tried playing with settings, I'm just stumped and it seems it's not working the way it's supposed to? How could it be different from the preview window in playmode?

    Is there anything I'm missing? I've tried scrubbing through the documentation and tutorials but nothings making this clear to me how to resolve this problem.
     
  2. frankcarey

    frankcarey

    Joined:
    Jul 15, 2014
    Posts:
    14
    Turns out the issue couldn't be reproduced in a clean project, but I was able to narrow it down in our project to having both: overflow: hidden with any kind of border radius set on the same element. Not sure why exactly this was the case, but we have an outline shader that uses Graphics.Blit() and while there were a typos in the above I fixed, as soon as I enabled "Clear Depthtexture" in the PanelSettings.asset, it worked.
     
    AgelessFrost likes this.
  3. AgelessFrost

    AgelessFrost

    Joined:
    Jan 26, 2019
    Posts:
    5