I recently updated my project to use Unity 2019, and for the most part it has been a seamless transition. However, I have encountered one issue when it comes to updating and image's sprite during runtime.
The game I am working on has a countdown at the start of each level (3, 2, 1, GO!). The countdown text is a series of sprites that are updated on a timer, and all of the sprites are the same resolution.
This worked fine before updating to Unity 2019, but now when the countdown gets to "GO!", it looks as though it has been squished horizontally.
I also ran a test where I ran the countdown in reverse (GO!, 1, 2, 3) and the opposite effect occurred. In this scenario, "GO!" looked normal, and 1 2 and 3 looked like they were expanded horizontally.
I set up a minimal test scene with only a Canvas/Image in it with the following script attached. The same behavior occurs as seen in the gifs below.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ImageSwapTest : MonoBehaviour
{
Image image; //Image component
[SerializeField] Sprite[] countDownSprites; //Array of sprites used to populate the image component
void Start()
{
image = GetComponent<Image>();
StartCoroutine(UpdateImage());
}
IEnumerator UpdateImage()
{
int counter = 0;
while (counter < sprites.Length)
{
yield return new WaitForSeconds(1); //Wait 1 second
image.sprite = countDownSprites[counter]; //Update the image to the next sprite
counter++;
}
}
}
Expected:
Actual:
If I reverse the order, then "GO!" is normal size and the numbers are expanded:
Image Properties:
As you can see, all 4 of the sprites have the same resolution. I am not sure what is causing them to be resized like this during runtime.
Did something change regarding the way images/sprites are handled in Unity 2019? Perhaps this is just a bug?