- Home /
Unity IDE crashes on 'Sprite.Create(Texture2D, Rect, Vector2)'
Hello, everyone. I have created a SpriteRenderer in a prefab as in a picture: 
Then created a new material RingBarOverlay and assigned it to. Then tried to create the Sprite programmatically, using Texture, loaded from png, as follows:
SpriteRenderer spriteRend = gameObject.GetComponent<SpriteRenderer> ();
speedTex = Resources.Load<Texture2D> ("RingBarOverlay/speed");
Sprite spr = Sprite.Create (speedTex, uiRect, new Vector2(uiRect.size.x, uiRect.size.y));
spriteRend.sprite = spr;
The trouble is: the debugging programme crashes at line, calling Sprite.Create(...).
What am I do wrong? Or is this a unity bug? p. s. google search helped nothing. Any help as appriciated, thank you for paying attention to the Issue!
Which version of Unity3D do you have? If you have version older than 4.3 you can catch likely editor crash case: http://issuetracker.unity3d.com/issues/sprite-dot-create-causes-unity-to-crash
Saying you get a crash doesn't help anyone help you. Post the contents of the Editor.log. Also, your code doesn't check that speedTex is loaded, so if anything goes wrong in the load, bad things (™) will happen.
Graham, in the code above insignifant lines (with check for null, for instance), are ommited. $$anonymous$$y texture is not null
Your answer