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 How do I edit vector image tint color of child of an element using UI Toolkit?

Discussion in 'UI Toolkit' started by JulianSlatlem, Jul 7, 2023.

  1. JulianSlatlem

    JulianSlatlem

    Joined:
    Dec 23, 2020
    Posts:
    4
    I am making a toolbar for my game, and I want to stylize my UI elements.
    Thus far, I have managed to make this without any custom elements:


    However, there are a few problems I have encountered with this approach, one of which is that I can't move the vector image attached to a button or toggle by itself (the square is a button, and the rest are toggles), so I have to resort to moving the whole button using the translate Y property; with this approach the hitbox of the button changes as well; so when I my cursor comes from underneath the button, it jitters (like you see at the end).

    If possible, I would like to make the buttons static, and move only the vector image in a child VisualElement.

    I have tried this too using a custom element, but now the problem is, I can't change the "Image Tint" property of the child, nor can I change the image (or I can, but it requires copying the image of the main element which doesn't help).

    I can change other properties like the background color, but I still can't seem to find a way to change the image or image tint.

    When I hover over the image tint property in the UI Builder inspector, the USS Property starts with "-unity" as supposed to only the property name itself like for "background-color".

    If this is just not possible, I hope that it will be implemented sometime later, as this would be a nice feature to have.
     

    Attached Files:

  2. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    969
    Are you looking for the
    -unity-background-image-tint-color
    property?
     
  3. JulianSlatlem

    JulianSlatlem

    Joined:
    Dec 23, 2020
    Posts:
    4
    Yes.

    Is it possible to access that property from code? I have tried for a little while, but can't get it to work properly.
     
  4. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    969
  5. JulianSlatlem

    JulianSlatlem

    Joined:
    Dec 23, 2020
    Posts:
    4
  6. JulianSlatlem

    JulianSlatlem

    Joined:
    Dec 23, 2020
    Posts:
    4
    It works!
    Thank you so much for the help!

    I don't know how I didn't get it the first time. I guess I really am stupid after all.

    Now, the only major problem that remains is, moving the image whilst not changing the button's hitbox.
    Do you have any idea how to achieve that?

    And also, is it possible to make a drag and drop image selector like the "background-image" property as a custom property for use in the child?