简体   繁体   中英

Changing UI Image's sprite, preserve aspect ratio is checked but not working? Unity 2019.1.0f2

Changing UI Image's sprite, preserve aspect ratio is checked but not working. Version: Unity 2019.1.0f2

What happened

I updated to the latest software update for Unity which is Unity 2019.1.0f2.

Before when it was version 2018.3.12f, the UI Image's sprite changes normally. But now when I have updated it, it doesn't regain its aspect ratio and gets stretched.

When the sprite changes on the UI image, the aspect ratio/width and height changes for the image and when you go back to the original image, then it becomes stretched or compressed.

I thought it was because I updated my game Unity version but I reproduced it on a brand new Unity project and it is doing the exact same thing.


How I reproduced it:

Code in Sprite[] and Image.

Code to change the sprite image to the next image in the sprite array.

Have a button to cycle through the images.

Run game.

Press button multiple times.

When it is cycled back to the first image again, it is now stretched or compressed and aspect ratio doesn't go back to its original size.


This bug has only been happening when I updated to the latest version Unity 2019.1.0f2 from 2018.3.12f.

Help would be appreciated. Thanks!

I had the same problem. I found a bad solution, but it works: set null to sprite before change sprite.

I think this is due to this: https://forum.unity.com/threads/use-sprite-mesh-option-recently-added-to-ui-image-what-is-this-for-exactly.604336/

I have also noticed this in Unity2019. It seems to be an issue with the sprites, not the image component.

My solution: 1) select the sprite in the inspector 2) set "Mesh Type" to "Full Rect"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM