- Home /
9 Slicing not working for UI Image
I followed the instructions here https://docs.unity3d.com/Manual/9SliceSprites.html
But I still can't get my Image to resize properly. As I increase height it scales the top section. My understanding is that it should not scale the top, bottom, left or right sections of the images if I am stretching the sprite to make it bigger.
Lots of posts on this topic but no solution that I could find.
I am not using scale. I am increasing height.
Bumping this. At last just tell me that it doesn't work. And hasn't for the last 5 years. And that Unity doesn't give a damn. Cuz, hey, why should anything work
Great job Unity! Really top notch!!!
Hmmm. Answer still too short ...
Why don't think fix this stuff? Are they afraid that fixing bugs will break things?
Answer by Bunny83 · Jul 09, 2021 at 09:34 AM
I don't see anything wrong here. It works perfectly as it should. You may have the wrong idea about a 9 slice? There are 9 sections, lets label them like this:
// /-----------------\
// | 1 | 2 | 3 |
// |-----------------|
// | 4 | 5 | 6 |
// |-----------------|
// | 7 | 8 | 9 |
// \-----------------/
Note that section 1, 3, 7 and 8 are the only sections that are not scaled.
Section 2 and 8 are only scaled horizontally. So their height stay the same, but their width changes.
Section 4 and 6 are only scaled vertically. So their width stay the same but their height changes.
Section 5 is the only section that is scaled in both axes.
So you can not have a nicely designed fixed sized header section that somehow, magically adjusts it's width without stretching. So Section 2 and 8 have to be designed so they can be stretched horizontally while section 4 and 6 need to be designed so they can stretch vertically.
If you really want a fixed sized element, you have to ensure that the element actually has the designed fixed size.
edit
Note that there is the draw mode "tiled" which does not stretch the image sections but rather tiling it. However the image sections need to be designed in a way that tiling makes sense which it doesn't for your image example.
Thanks Bunny, but you can clearly see that the top 3 sections are all being scaled vertically and are taller than their respective sections in the sprite. Maybe you want to look again at what I am doing as I think it's pretty clear from the images I posted.
This is a bug in Unity. Apparently half a decade old. And a really dumb one. That many have complained about. For years.
No, your image looks exactly as expected. Yes, the image on the right is larger than the preview image in the inspector because your image has a size of 1196 pixels and is displayed smaller in the preview since your inspector window is most likely not 1196 pixels wide. Regardless of that "downscale" in the preview of the inspector, the parts 1 and 3 are not distorted at all, only uniformly larger than the preview. However not because it's scaled up, but because the preview is scaled down.
Mea Culpa, I finally get it. It's because the source image is too big. Thank you!
Your answer
