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!

2 Answers

Community On

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:

Harrison Walters On

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"