Search Unity

UIElements remove background image on Button

Discussion in 'UI Toolkit' started by jwvanderbeck, Mar 14, 2019.

  1. jwvanderbeck

    jwvanderbeck

    Joined:
    Dec 4, 2014
    Posts:
    825
    Hi all,

    I am trying to use buttons to make clickable elements, but I don't want them styled as buttons. In IMGUI I did this by styling them as text and I'm trying to do something similar in UIElements.

    I create a Button and set its backgroundImage to StyleValue<Texture2D>.nil yet when the element is drawn it still has the default backgroundImage.

    Setting the backgroundImage manually to None in the UIElementsInspector works as expected, but I just can't seem to get the code to do the same.

    Code (CSharp):
    1. jobItem.Add(new Button()
    2. {
    3.     text = job,
    4.     style =
    5.     {
    6.         fontSize = 14,
    7.         height = 40,
    8.         backgroundImage = StyleValue<Texture2D>.nil
    9.     }
    10. });
     
  2. AlexandreT-unity

    AlexandreT-unity

    Unity Technologies

    Joined:
    Feb 1, 2018
    Posts:
    377
    Hi jwvanderbeck, try setting the backgroundImage to null instead.
     
  3. jwvanderbeck

    jwvanderbeck

    Joined:
    Dec 4, 2014
    Posts:
    825
    Thanks that worked. Useful code completion actually hurt for once lol.