Can I access previously downloaded textures?

Hi guys, didn’t found anything related. I’ll be using www to get textures but once the player opens the game again I don’t want to download the previously downloaded textures, is there a way to access these downloaded textures? Are they stored in some folder?

No, things you download through WWW are dropped unless you store them yourself (exception: www.LoadFromCacheOrDownload for assetbundles)

If you store the texture after a download then you can access it through WWW and the file:// protocol again (if its standalone or mobile)
If it is the webplayer, just do the request again and the browser will provide it out of the cache.


Edit, re Dreamora’s incredibly useful comment below, here’s some tested code version of that! Hope it helps someone!

Call it with a gameObject which has a flat plane the size you want with an example image on it, and the URL in question of some jpg.

private IEnumerator Paint(GameObject go, string url)
	{
	go.renderer.material.mainTexture =
	    new Texture2D(512,512, TextureFormat.DXT1, false);
	
	var www = new WWW(url);
	yield return www;
	www.LoadImageIntoTexture(
	    go.renderer.material.mainTexture as Texture2D);
	}

private IEnumerator PaintCachewise(GameObject go, string url)
	{
	go.renderer.material.mainTexture =
	    new Texture2D(512,512, TextureFormat.DXT1, false);
	
	Debug.Log("url "+url);
	
	string justFilename = System.IO.Path.GetFileName(url);
	Debug.Log("justFilename " +justFilename);
	
	string localName =
	    Application.persistentDataPath + "/" + justFilename;
	Debug.Log("localName " + localName);
	
	if ( System.IO.File.Exists( localName ) )
		Debug.Log("			It Exists");
	else
		Debug.Log("			-- does not exist yet");
	
	if ( System.IO.File.Exists( localName ) )
		{
		// proudly load from cache with confidence
		
		var ccc = new WWW( "file://" + localName);
		yield return ccc;
		ccc.LoadImageIntoTexture(
	            go.renderer.material.mainTexture as Texture2D);
		
		Debug.Log("loaded from speedy local cache.");	
		}
	else
		{
		var www = new WWW(url);
		yield return www;
		www.LoadImageIntoTexture(
	            go.renderer.material.mainTexture as Texture2D);
	
		System.IO.File.WriteAllBytes( localName, www.bytes );
		
		Debug.Log("loaded from planetary cloud data system - "
	             +" and saved to device SSD");
		}
	
	// per Dreamora http://answers.unity3d.com/answers/436748 !!
	}

here’s a little more generic cached WWW utility function. you will need to point the hash function to something that you have and the StartCoroutine come from some monobehaviour. just use this instead of your normal WWW constructor.

static public WWW getCachedWWW(string url)
    {
        string filePath = Application.persistentDataPath;
        filePath += "/" + GetInt64HashCode(url);
        string loadFilepath = filePath;
        bool web = false;
        WWW www;
        bool useCached = false;
        useCached = System.IO.File.Exists(filePath);
        if (useCached)
        {
            //check how old
            System.DateTime written = File.GetLastWriteTimeUtc(filePath);
            System.DateTime now = System.DateTime.UtcNow;
            double totalHours = now.Subtract(written).TotalHours;
            if (totalHours > 300)
                useCached = false;
        }
        if (useCached)
        {
            string pathforwww = "file://" + loadFilepath;
            Debug.Log("TRYING FROM CACHE " + url + "  file " + pathforwww);
            www = new WWW(pathforwww);
        }
        else
        {
            web = true;
            www = new WWW(url);
        }
        yoursomesclass.instance.StartCoroutine(doLoad(www, filePath, web));
        return www;
    }

    static IEnumerator doLoad(WWW www, string filePath, bool web)
    {
        yield return www;

        if (www.error == null)
        {
            if (web)
            {
                //System.IO.Directory.GetFiles
                Debug.Log("SAVING DOWNLOAD  " + www.url + " to " + filePath);
               // string fullPath = filePath;
                File.WriteAllBytes(filePath, www.bytes);
                Debug.Log("SAVING DONE  " + www.url + " to " + filePath);
                //Debug.Log("FILE ATTRIBUTES  " + File.GetAttributes(filePath));
                //if (File.Exists(fullPath))
               // {
                //    Debug.Log("File.Exists " + fullPath);
               // }
           }
            else
            {
                Debug.Log("SUCCESS CACHE LOAD OF " + www.url);
            }
        }
        else
        {
            if (!web)
            {
                File.Delete(filePath);
            }
            Debug.Log("WWW ERROR " + www.error);
        }
    }