- Home /
Problems with Sprite.Create in 5.0.1
Hello!
I am building a photo gallery with Unity 5 but since a few releases (probably after 5.0.0p1) I am having problems with procedurally populating this gallery. I have an object list that contains Sprites ("2D and UI"). In my gallery script I instantiate an UI.Image, then grab an object from the object list and cast it as a sprite to set it as the sprite for the instantiated image:
var img= (UI.Image)Instantiate(imagePrefab);
// Cast object from list as Texture2D
var tex = objectList[i] as Texture2D;
var newSprite = Sprite.Create(tex, new Rect(0f, 0f, tex.width, tex.height), Vector2.zero);
newSprite.name = tex.name;
img.sprite = newSprite;
This worked perfectly fine in previous releases but now the image stays empty. In the inspector the sprite is still assigned to the image correctly but it does not show up on screen. All I see are empty RectTransforms with no images...
Can someone help please?
Your answer
Follow this Question
Related Questions
How do i change SpriteRenderer.Sprite 2 Answers
Image vs Sprites performance 1 Answer
Messy tiled sprites 1 Answer
Sprite Becoming Blurry 2 Answers
Draw a Sprite Round 1 Answer