How to use WWW to load Local files?

Hi guys, when I first thought of doing this, I thought there would be no problem but now I’m stuck for hours in this.

What kind of path should I provide to the WWW constructor?

It has to have “file://” as protocol?

Do I need to yield?

here is my current, not working, implementation:

public class loadwww : MonoBehaviour {

	public Texture2D tex;
	public WWW w;

	void Start()
	{
		LoadTex();
	}

	void LoadTex ()
	{
		w = new WWW ("file://Users/Paulo/Desktop/img_2013_008_original.jpg");
	}

	void Update () 
	{
		if(w.isDone)
		{
			Debug.Log("done");
			tex = w.texture;
		}
	}
}

And the error it’s presenting:

You are trying to load data from a www stream which had the following error when downloading.
Couldn’t open file /Paulo/Desktop/img_2013_008_original.jpg
UnityEngine.WWW:get_texture()
loadwww:Update() (at Assets/MakeLy/Scripts/loadwww.cs:24)

ANSWER:

The root in OSX is /Users, so the correct URL is file:///Users/[…] with three / instead of only two.

You lack drive info in your URL. It probably has to be “file:///c://Users/…”. And regarding ‘yield’ - yes - you should use WWW loading inside coroutine, like in this example.

The root in OSX is /Users, so the correct URL is file:///Users/[…] with three / instead of only two.

You need to add your drive to the path:
“file://c://Users/…”

I am loading an image stored to the local drive. The Application.persistentDataPath string to the file does not include the prepended “file://”. Instead of just manually adjusting the string I am using UriBuilder to achieve the same result, perhaps with more portability:

String tFullPathName = Application.persistentDataPath + "/" + folderName + "/" + filename;
UriBuilder tURIBuilder = new UriBuilder( tFullPathName );
tURIBuilder.Scheme = "file"; // Uri.UriSchemeFile is not available when building for UWP (?). It is the string "file" so I just use the string here. 
WWW tWWW = new WWW( tURIBuilder.ToString() );