首页 > 代码库 > Unity3D之报错 - Instantiating a non-readable texture is not allowed!

Unity3D之报错 - Instantiating a non-readable texture is not allowed!

报错:

Instantiating a non-readable wall_plank texture is not allowed! Please mark the texture readable in the inspector or dont instantiate it.

情景描述:

  加载AssetBundle时,把加载出来的所有Object对象都Instantiate实例化了,实例化过程中出现该错误。

解决方案:

  方案1:把要使用贴图文件(如*.Tga)的属性(如下图)设置Read/Write Enabled为true,对应的程序参数是TextureImporter.isReadable,即可以正常实例化。它决定了贴图的存放位置,设置为可读写,在移动平台中,会将其同时放在显存和内存中,导致内存占用增加一倍。

      技术分享

  方案2:资源加载时设置type

www.assetBundle.LoadAll(typeof(GameObject))

  方案3:遍历资源时添加判断

//通过字符串比较
"UnityEngine.GameObject".Equals(obj.GetType().ToString())
//通过类型比较
typeof(GameObject).IsInstanceOfType(obj)

 

参考:

【1】:http://blog.csdn.net/zzxiang1985/article/details/43339273  Unity+NGUI性能优化方法总结

【2】:http://www.u3dol.com/bbs/d/201406/6109 

Unity3D之报错 - Instantiating a non-readable texture is not allowed!