- Home /
problems getting text string from assetbundle
I'm trying to get a text file from an assetbundle and put it in a string variable. I am successfully able to load the assetbundle and take a texture from the bundle and apply it to an object, but something is wrong with my code for grabbing a txt file hat1_info.txt and trying to put it into a TextAsset. I don't get any errors except the textasset is null.
downloadAssetBundle();
function downloadAssetBundle(){
var urlEditor = "file:///Users/dan/Desktop/hat1bundle.unity3d";
var hat:GameObject;
var bundle:AssetBundle;
// Start a download of the given URL
if (Application.platform == RuntimePlatform.OSXEditor){
var www:WWW = WWW.LoadFromCacheOrDownload (urlEditor, 1);
yield www;
bundle = www.assetBundle;
makeitso(bundle);
}
}
function makeitso(bundle:AssetBundle){
Debug.Log("making it so");
//this works GameObject.Find("Sphere").renderer.material.mainTexture=bundle.Load("hat1_texture",Texture);
//this does not work gives back null
var txt:TextAsset = bundle.Load("hat1_info", typeof(TextAsset)) as TextAsset;
Debug.Log(txt); //gives back null
Debug.Log(txt.text);
var s=txt.text;
Debug.Log(s);
}
Follow up. I can load the file fine if I put it in the resources folder using Resources.Load. Also I have a gameObject in the assebundle that also loads fine. So A texture loads fine and a gameObject loads fine but it doesn't like that text file, but resources load can handle it.
Answer by dansav · Sep 07, 2012 at 01:56 AM
I found the problem.
The problem is even though I updated my assetbundle, the download function
WWW.LoadFromCacheOrDownload.
was loading an older cached version.
I found the answer by checking AssetBundle.Contains and finding out it was false. So I was not working with the assetbundle I thought I was working with.
Dan