How to load a sprite from streamingassets instead of resources?

UPDATE: No one has any ideas on this one? I would have thought this would be a fairly simple problem to solve. It is a particularly useful thing to be able to do if you want the end-user to be able to easily mod your application with new images …

I’d basically like to do the following:

SpriteRenderer sr = myGameObject.GetComponent<SpriteRenderer>();
sr.sprite = (Sprite)Resources.Load<Sprite>("mySprite");

… except, I’d like mySprite to come from the streamingassets directory instead of the Unity resources.

Is this possible?

Can anyone give me an example of how this is done?


I found the solution. You need to use the WWW class to load a local file. You can access that file as a Texture, and then you create a Sprite using that Texture.

public IEnumerator LoadSprite(string absoluteImagePath)
    string      finalPath;
    WWW         localFile;
    Texture     texture;
    Sprite      sprite;

    finalPath = "file://" + absoluteImagePath;
    localFile = new WWW(localFile);

    yield return localFile;

    texture = localFile.texture;
    sprite = Sprite.Create(texture as Texture2D, new Rect(0, 0, texture.width, texture.height),;

I hope that’s useful for your case too :wink:

I do this which seems the same way you are?

public IEnumerator LoadStreamingAsset(string path) { 

		WWW www = new WWW("file://" + System.IO.Path.Combine(Application.streamingAssetsPath, "IMG_3020.JPG"));

		while (!www.isDone) {

			yield return null;

		if (!string.IsNullOrEmpty(www.error)) {
			Debug.Log (www.error);
			yield break; 
		else {

			photoSphere.GetComponent<Renderer> ().material.mainTexture = www.texture;

		yield return 0;