Cast Texture2d to Sprite

string url = “”;

 www = new WWW(url);
portraitSprite.sprite = (Sprite)www.texture;
    private IEnumerator WaitForWWW() {
        yield return www;	


Cannot convert type ‘UnityEngine.Texture2D’ to 'UnityEngine.Sprite

Any ideas? new to Unity…

A sprite isn’t a texture. You can create a sprite from a texture; see the docs for Sprite, specifically the Create function.

I just solved exactly same problem with Sprite.Create. It is working in editor, but not on device. It looks that device can not use Sprite.Create, so I have to use texture and RawImage.

IEnumerator Start()
WWW www = new WWW(url);
yield return (www);
gameObject.GetComponent().overrideSprite = Sprite.Create(www.texture, new Rect(0, 0, 900, 360), new Vector2(0.5f, 0.5f));

Hi, this can help

// reading texture from images in system local


public static Texture2D LoadPNG(string filePath)
Texture2D tex = null;
byte fileData;

    if (File.Exists(filePath))
        fileData = File.ReadAllBytes(filePath);
        tex = new Texture2D(2, 2);
        tex.LoadImage(fileData); //..this will auto-resize the texture dimensions.
    return tex;


then save the texture from LoadPNG function


mytexture = LoadPNG(thumbnailpath);
obj.GetComponentInChildren().sprite = Sprite.Create(mytexture, new Rect(0.0f, 0.0f, mytexture.width, mytexture.height), new Vector2(0.5f, 0.5f), 100.0f);