当前位置:网站首页>Unity开发bug记录100例子(第1例)——打包后shader失效或者bug
Unity开发bug记录100例子(第1例)——打包后shader失效或者bug
2022-06-30 16:43:00 【华为云】
bug描述
最近遇到一个bug,项目中用shader实现文字边框描边,在unity中好好的,但是打包出来,描边消失了,纳尼???消失就算了,还出现了许多不明出处的XXX。一打开日志发现:ArgumentNullException: Value cannot be null. Parameter name: shader
bug查找
然后疯狂百度。。。无果,于是尝试着找问题。
在unity中,白色字添加黑色边框,显示效果如下:
打包运行如下:
bug分析
推测出是打包造成的shader不正常,于是百度:打包shader出bug。果不其然,找到了。
原来是在Unity中,Shader是从代码中进行加载的,编辑器中并没有引用。在编辑器中运行项目没有问题,但当项目发布到移动平台,如ios、android、UWP之后,游戏中并不能找到对应的shader。因为Shader在场景中并未被引用,所以没有被打包。
详细原因请见http://www.javashuo.com/article/p-gkbxubfx-oc.html
bug解决
解决办法1
Editor——Project Setting——Graphics,展开Tier Settings
将Medium栏取消使用默认值勾选,并设置Standard Shader Quality值为Medium等,具体设置如下图:
设置如下:
运行发现,并没有什么卵用,pass。
解决办法2
在ProjectSettings里面的Graphics,添加上修改的打包有问题的shader
运行发现,完美解决,感谢度娘!
解决办法3
将shader放在如下文件夹里:项目名/Resources/
如果没有Resources文件夹,需要创建一个即可,打包运行,完美解决!
解决办法4
通过分析发现,是因为项目里使用到的shader被打包成了ab,加载ab使用的是Shader.Find方法。
Shader shaderOutline = Shader.Find(c_strShaderName);
而打包成ab后的shader不能使用该静态加载方法,需通过加载ab的形式加载shader。于是添加shader的ab加载方式。在AssetManager.cs里天啊及
public Shader LoadShader(string path) { return LoadAsset<Shader>(path); }
在加载shader的时候使用下面方式加载:
var asset = AppFacade.Instance.GetManager<AssetManager>();var shader = asset.LoadAsset<Shader>("Shader/TextOutline.shader");Shader shaderOutline = shader;
打包发现,完美结局!但是突然我正想修改某个使用了该shader的预制是,打开预制发现:NullReferenceException: Object reference not set to an instance of an object
纳尼??报错了,定位代码一看,正式上面修改的地方。恍然大悟,少了一个判断操作,需要根据是否是ab模式去加载shader,于是慢手慢脚的修改了代码。
if (GameConst.BundleMode){ var asset = AppFacade.Instance.GetManager<AssetManager>(); var shader = asset.LoadAsset<Shader>("Shader/TextOutline.shader"); Shader shaderOutline = shader; graphic.material = new Material(shaderOutline);}else{ Shader shaderOutline = Shader.Find(c_strShaderName); graphic.material = new Material(shaderOutline);}
边栏推荐
- 现在玩期货需要注意什么,在哪里开户比较安全,我第一次接触
- 【剑指Offer】52. 两个链表的第一个公共节点
- 【义修换届大礼包】
- Booking UI effect implemented by svg
- C语言结构体
- 流批一体在京东的探索与实践
- 每日面试1题-蓝队基础面试题-应急响应(1)应急响应基本思路流程+Windows入侵排查思路
- ASP. Net password encryption and password login
- Ardunio esp32 obtains real-time temperature and humidity in mqtt protocol (DH11)
- splitting. JS password display hidden JS effect
猜你喜欢
Flutter custom component
AnimeSR:可学习的降质算子与新的真实世界动漫VSR数据集
Deep understanding of JVM (VI) -- garbage collection (III)
Apache 解析漏洞(CVE-2017-15715)_漏洞复现
New research of HKUST & MsrA: about image to image conversion, finishing is all you need
Conception d'un centre commercial en ligne basé sur SSH
Solve the problem of unable to connect to command metric stream and related problems in the hystrix dashboard
【网易云信】播放demo构建:无法将参数 1 从“AsyncModalRunner *”转换为“std::nullptr_t”**
IEEE TBD SCI影响因子提升至4.271,位列Q1区!
Small tools (3) integration knife4j3.0.3 interface document
随机推荐
[machine learning] K-means clustering analysis
IEEE TBD SCI impact factor increased to 4.271, ranking Q1!
编译生成busybox文件系统
Develop those things: how to add text watermarks to videos?
Radio and television 5g officially set sail, attracting attention on how to apply the golden band
Thinking on large file processing (upload, download)
2022上半年盘点:20+主流数据库重大更新及技术要点汇总
Development details of NFT casting trading platform
大文件处理(上传,下载)思考
Ten thousand volumes - list sorting [01]
Php8.0 environment detailed installation tutorial
What should I pay attention to when playing futures? Where is safe to open an account? It's my first contact
Nielseniq welcomes dawn E. Norvell, head of retail lab, to accelerate the expansion of global retail strategy
Babbitt | yuanuniverse daily must read: minors ask for a refund after a reward. The virtual anchor says he is a big wrongdoer. How do you think of this regulatory loophole
Redis (IV) - delete policy
Nft: unlimited possibilities to open the era of encryption Art
TCP session hijacking based on hunt1.5
Send the injured baby for emergency medical treatment. Didi's driver ran five red lights in a row
Tubes响应性数据系统的设计与原理
后渗透之文件系统+上传下载文件