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

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!

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.

And you can to use BuildAssetBundleOptions.DeterministicAssetBundle parameter in BuildPipeline.BuildAssetBundle() method. In this case bundle will create with texture project settings.