- Home /
Sprite image not showing up when assigned to Texture2D
I have a UI image component that I am trying to give a new sprite at runtime from the following code:
public Image overlayImage;
public Texture2D puzzleImage;
[...]
Rect overlayRect = new Rect(overlayImage.rectTransform.localPosition.x, overlayImage.rectTransform.localPosition.y, puzzleImage.width, puzzleImage.height);
overlayImage.sprite = Sprite.Create(puzzleImage, overlayRect , new Vector2(0, 0), 100.0f);
overlayImage.SetNativeSize();
However it does not show up in game, the image loads in as it correctly assigns the size of the image, any help appreciated.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612134146im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
how Can I make a UI Image Blink On And Off 5 Answers
UI Image source image not changing 2 Answers
Question about an inventory system idea 2 Answers
Saving image in a variable purely through code? 1 Answer
Destroy UI Image 1 Answer