Scale sprite 9-slicing in background

I am now trying to migrate to the new UI Toolkit. But I found a problem with the sprites in the background, which are cut using the “9-slicing” technology. The sprite itself is 2k pixels in size. And when I set it to the background of a VisualElement - the size of the corners is too huge and takes up all the space (this can be seen in the attached image). In the old Unity UI, I fixed this with the “Pixel Per Unit Multiplie” option.
How to fix this in the new UI Toolkit?

7914925--1009651--unnamed2.png
7914925--1009654--unnamed3.png

1 Like

Hello, we have a fix in the 2022.2 branch that takes the “pixels per unit” value into account. We also added a “-unity-slice-scale” style to modify it on a per-element basis. Unfortunately, this cannot be backbported to earlier Unity versions.

4 Likes

@mcoted3d any workaround you can think of for this problem? I’m also in the process of migrating to UIToolkit but I’m on 2021 and planning to release the update with 2021LTS. 2022 would be to late for us :confused:

2 Likes

Not yet, but after having a second look, we may be able to make a 2021 backport of the fix that takes the sprite’s pixelPerUnit value into account for the slices. I’ll keep in touch regarding this. We won’t be able to bring the customizable -unity-slice-scale style however.

1 Like

2021 LTS is approaching, but we’d be very glad if the backport could make it :slight_smile:

The backport landed for 2021.2.3f1. This means UI Toolkit will take the Sprite’s pixels-per-unit value into account when drawing 9-sliced sprites.

We couldn’t backport the slice adjustment style (-unity-slice-scale) which we introduced in 2022.2, however. So the only way to adjust the slice scaling is to change the Sprite’s PPU value.