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.
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;
}
}
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 instead. Hope Unity3D-Team would be inproved this problem.
And you can to use BuildAssetBundleOptions.DeterministicAssetBundle parameter in BuildPipeline.BuildAssetBundle() method. In this case bundle will create with texture project settings.
THANK YOU VERY MUCH! It is very useful code!
– Nick_lznThank you so much. Just what I needed and an extremely elegant solution!
– aryaman1994please tell me how to use that function, I added the class to "Editor" folder, but the error continues
– Weedliam