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

How to correctly add icon to button (UXML warning)

Discussion in 'UI Toolkit' started by Xarbrough, Jan 29, 2020.

  1. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,184
    The docs state, that a Button control may not contain child elements and my UXML also shows me a warning:

    The element Button cannot contain child element Bla because the parent element's content model is empty.

    However, visually, this seems to work. I have a button with an icon.

    Am I doing something wrong or is this warning misleading?

    Code (CSharp):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <engine:UXML
    3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    4.     xmlns:engine="UnityEngine.UIElements"
    5.     xmlns:editor="UnityEditor.UIElements"
    6.     xsi:noNamespaceSchemaLocation="../UIElementsSchema/UIElements.xsd"
    7. >
    8.  
    9.   <engine:Label text="Time Scale"/>
    10.   <engine:Slider/>
    11.   <editor:FloatField name="Time"/>
    12.   <editor:FloatField name="MaxTime"/>
    13.   <engine:Button name="Reset">
    14.     <engine:VisualElement name="ResetIcon"/>
    15.   </engine:Button>
    16.  
    17. </engine:UXML>
     
  2. MattM_Unity

    MattM_Unity

    Unity Technologies

    Joined:
    Aug 18, 2017
    Posts:
    45
    Hello Xarbrough!

    Would you be able to tell me what version are you using?
     
  3. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,184
    2019.3.0f5. Thanks for looking at this!
     
    Last edited: Jan 30, 2020
  4. uMathieu

    uMathieu

    Unity Technologies

    Joined:
    Jun 6, 2017
    Posts:
    384
    The warning is just a suggestion as nothing really forbids you from doing it further down the line. We'll update the generated schema to reflect this.
     
    Xarbrough likes this.
  5. MattM_Unity

    MattM_Unity

    Unity Technologies

    Joined:
    Aug 18, 2017
    Posts:
    45
    It doesn't seem like I reproduce the issue on 2019.3.0f6 using your UXML snippet.

    Could you try to upgrade to the latest version and let me know if you still have this problem?
     
    Xarbrough likes this.
  6. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,184
    I checked my project in 2019.3.0f6 and indeed, the IDE warnings about buttons not allowing children have disappeared. :)
     
  7. StephanieRowlinson

    StephanieRowlinson

    Joined:
    Jul 23, 2014
    Posts:
    136
    I'm on 2019.3.0f6 and still seeing this warning in Visual Studio, but not in Unity. Anything I can do to get rid of this?
    upload_2020-1-30_14-34-39.png
     
  8. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,184
    StephanieRowlinson likes this.
  9. MattM_Unity

    MattM_Unity

    Unity Technologies

    Joined:
    Aug 18, 2017
    Posts:
    45
    @Xarbrough Glad to see it is also fixed for you! :) Thanks for letting me know!