Search Issue Tracker
By Design
Votes
0
Found in
2018.4
2019.3.4f1
2020.2
Issue ID
1267688
Regression
No
Sprite's rect is cropped when called with Texture2D.LoadImage right after Sprite creation
How to reproduce:
1. Open attached project "case1267688.zip" and scene "TestScene"
2. Enter Play Mode
3. Observe the Sprite B (the middle one) in the Game view
Expected result: The loaded image is displayed correctly
Actual result: The loaded image is displayed incorrectly
Reproducible with: 2018.4.26f1, 2019.4.7f1, 2020.1.1f1, 2020.2.0a20
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Test Runner’s vertical scrollbar overlaps with the up and down arrows and upper toolbar tabs when the window is minimized
- The Input Field view is not updated when deleting lines of text
- The scrollbar does not respect empty lines in the Input Field
- “Texture Atlas Viewer“ button text overlaps another button when the UI Toolkit Debugger is narrowed
- Thresholds are no longer automatically calculated after deleting Motion fields in Blendtrees
Resolution Note:
This is as expected. Sprite UVs are calculated the first time it is rendered.
A.sprite = Sprite.Create(texture2D, new Rect(0, 0, 64, 64), Vector2.one * 0.5f);
yield return null; <- Since rendering is happening here, the UV for the Sprite is now set to take up the whole sprite
yield return null;
B.sprite = Sprite.Create(texture2D, new Rect(0, 0, 64, 64), Vector2.one * 0.5f);
texture2D.LoadImage(File.ReadAllBytes(Application.dataPath + @"\A_Simple_128x128_Image.png"));
C.sprite = Sprite.Create(texture2D, new Rect(0, 0, 128, 128), Vector2.one * 0.5f);
// When the first render happens, B.sprite will be calculated based on the the new data in texture2D which is now 128x128