2

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:

enter image description here

Actual:

enter image description here

If I reverse the order, then "GO!" is normal size and the numbers are expanded:

enter image description here

Image Properties:

enter image description here

enter image description here

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?

Alex Myers
  • 6,196
  • 7
  • 23
  • 39

2 Answers2

3

Same thing happened to me. The fix was:

  1. Select Texture in Unity
  2. Change Sprite Mode > Mesh Type from "Tight" to "Full Rect"
Alex Myers
  • 6,196
  • 7
  • 23
  • 39
George Mincila
  • 529
  • 5
  • 17
1

Setting the sprite to null before setting it also works as per this answer - https://stackoverflow.com/a/55827303

Setting Image Type from Simple to Filled also fixed it for me.

st4rdog
  • 93
  • 1
  • 6