Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

[UIBuilder] How to inheret pixel size of background image?

Discussion in 'UIElements' started by TextusGames, Oct 7, 2019.

  1. TextusGames

    TextusGames

    Joined:
    Dec 8, 2016
    Posts:
    143
    Is there a way?
     
  2. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    289
    We have the
    Image
    element for this but the UIBuilder does not currently support this element. You'd have to add it in code. You can use a dummy
    VisualElement
    in the UIBuilder to mark where the
    Image
    element should go and then it should be pretty easy to swap it in C#. This is a temporary issue.

    But I'd encourage you to try not using auto-sizing elements for your images. It means that some of your layout is not described in USS but instead it comes from a random file. If you resave your image with a different size, you can break your UI's layout without knowing. It's usually better to have the UI drive the size of the images it uses. But I say this without knowing your exact use case. :)
     
    TextusGames likes this.