- Home /
Instantiating Texture2D Object get non-readable error about AssetBundle
hi guys! I got an error when i Instantiate the mainAsset of the AssetBundle, which it is like: Instantiating a non-readable '001' texture is not allowed!Please mark the texutre readable in the inspector or don't instantiate it.
the code:
Texture2D tex = Instantiate(www.assetBundle.mainAsset) as Texture2D;
//some assign
www.assetBundle.Unload(false);
I change the Texture-Type to Advance,and enable the read/write-Enable;then Build AssetBundle. But it's not working.Still get same error.
the Build code:
BuildPipeline.BuildAssetBundle(object, null, path, BuildAssetBundleOptions.ColletDependencies | BuildAssetBundleOptions.CompleteAssets);
Thanks in Advance!
Answer by MOlmstead · Feb 20, 2014 at 03:44 PM
I'm having this same problem and I've come to the conclusion that it is not possible. I have a bundle with a texture that I want to save to disk (the reason why is irrelevant). When I call EncodeToPNG() I get the same error as Nick_Izn.
The problem is the fact that "Read/Write Enabled" is stored in the texture's metafile but BuildAssetBundle doesn't pack meta files and I see no way to make it do so, short of making the entire bundle a scene.
Your conclusion sounds reasonable. Finally, I change my solution with IO.FILE operation by my self ins$$anonymous$$d. Hope Unity3D-Team would be inproved this problem.
Answer by ereneld · Sep 24, 2014 at 10:20 PM
I had the same issue. The solution is changing Texture import settings on asset bundle creation using OnPreprocessTexture function. You can use the example class to change texture import setting on asset bundle creation.
using UnityEngine;
using UnityEditor;
class TextureImporterExample : AssetPostprocessor {
void OnPreprocessTexture () {
TextureImporter textureImporter = assetImporter as TextureImporter;
//textureImporter.compressionQuality = (int)TextureCompressionQuality.Best;
//textureImporter.textureFormat = TextureImporterFormat.RGB24;
textureImporter.isReadable = true;
}
}
THAN$$anonymous$$ YOU VERY $$anonymous$$UCH! It is very useful code!
Thank you so much. Just what I needed and an extremely elegant solution!
please tell me how to use that function, I added the class to "Editor" folder, but the error continues
Answer by Robotron18 · Apr 22, 2015 at 12:05 PM
And you can to use BuildAssetBundleOptions.DeterministicAssetBundle parameter in BuildPipeline.BuildAssetBundle() method. In this case bundle will create with texture project settings.
http://docs.unity3d.com/ScriptReference/BuildAssetBundleOptions.DeterministicAssetBundle.html
Your answer
Follow this Question
Related Questions
Codes unavailable in C# 0 Answers
Get Asset Preview (3.5) 1 Answer
How to partially reveal texture of a plane or object 1 Answer
How can i reset unity to default? 0 Answers