当前位置:网站首页>100 examples of bug records of unity development (the first example) -- shader failure or bug after packaging
100 examples of bug records of unity development (the first example) -- shader failure or bug after packaging
2022-06-30 18:12:00 【Hua Weiyun】
bug describe
Recently I met a bug, The project used shader Implement text border stroke , stay unity Medium good , But pack it up , The stroke disappeared , what ??? Just disappear , There have also been many cases of unknown origin XXX. Once you open the log, you will find :ArgumentNullException: Value cannot be null. Parameter name: shader
bug lookup
Then crazy Baidu ... To no avail , So try to find the problem .
stay unity in , White words with black borders , The display effect is as follows :
The package runs as follows :
bug analysis
It is speculated that it is caused by packaging shader Is not normal , So Baidu : pack shader Out bug. Sure enough , eureka .
It turned out to be Unity in ,Shader Is loaded from the code , There is no reference in editor . There is no problem running the project in the editor , But when the project is released to the mobile platform , Such as ios、android、UWP after , There is no match in the game shader. because Shader Not referenced in the scene , So it wasn't packed .
For detailed reasons, please refer to http://www.javashuo.com/article/p-gkbxubfx-oc.html
bug solve
terms of settlement 1
Editor——Project Setting——Graphics, an Tier Settings
take Medium Column uncheck the default value , And set up Standard Shader Quality The value is Medium etc. , The specific settings are shown in the figure below :
Set as follows :
Run discovery , No eggs ,pass.
terms of settlement 2
stay ProjectSettings Inside Graphics, Add the modified package with problems shader
Run discovery , Perfect solution , Thanks to Du Niang !
terms of settlement 3
take shader Put it in the following folder : Project name /Resources/
without Resources Folder , You need to create one , Packaging operation , Perfect solution !
terms of settlement 4
Through analysis, we found that , It is because of the shader Packed into ab, load ab It uses Shader.Find Method .
Shader shaderOutline = Shader.Find(c_strShaderName);
And packaged into ab After shader You cannot use this static loading method , You need to load ab The form of loading shader. Then add shader Of ab Loading mode . stay AssetManager.cs Oh, my God
public Shader LoadShader(string path) { return LoadAsset<Shader>(path); }
In the load shader Use the following method to load :
var asset = AppFacade.Instance.GetManager<AssetManager>();var shader = asset.LoadAsset<Shader>("Shader/TextOutline.shader");Shader shaderOutline = shader;
I found , The perfect ending ! But all of a sudden, I was just trying to modify someone who used this shader The prefabrication of is , Open prefabrication and find :NullReferenceException: Object reference not set to an instance of an object
what ?? Wrong report , Look at the location code , The formal changes above . See light suddenly , One judgment operation is missing , It depends on whether it is ab Mode to load shader, So I modified the code slowly .
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);}
边栏推荐
- Unity实战之一个脚本实现雷达图
- DeFi借贷协议机制对比:Euler、Compound、Aave和Rari Capital
- Only black-and-white box test is required for test opening post? No, but also learn performance test
- 腾讯云安装mysql数据库
- Word中添加代码块(转载)
- [零基础学IoT Pwn] 环境搭建
- 力扣解法汇总1175-质数排列
- Nft: unlimited possibilities to open the era of encryption Art
- 【剑指Offer】53 - I. 在排序数组中查找数字 I
- Several points in MySQL that are easy to ignore and forget
猜你喜欢
基于eNSP的校园网设计的仿真模拟
Post office - post office issues (dynamic planning)
Mo Tianlun salon | Tsinghua qiaojialin: Apache iotdb, originated from Tsinghua, is building an open source ecological road
Spin lock exploration
Small tools (3) integration knife4j3.0.3 interface document
2022上半年盘点:20+主流数据库重大更新及技术要点汇总
DeFi借贷协议机制对比:Euler、Compound、Aave和Rari Capital
大文件处理(上传,下载)思考
Redis (I) - data type
Key to understanding the trend of spot Silver
随机推荐
MySQL之零碎知识点
Do fresh students get a job or choose a job after graduation?
Php8.0 environment detailed installation tutorial
ABAP-发布Restful服务
5g business is officially commercial. What are the opportunities for radio and television?
Word中添加代码块(转载)
Partition marble (multiple knapsack + binary optimization)
每日面试1题-如何防止CDN防护被绕过
MIT science and Technology Review released the list of innovators under the age of 35 in 2022, including alphafold authors, etc
Unity开发bug记录100例子(第1例)——打包后shader失效或者bug
Only black-and-white box test is required for test opening post? No, but also learn performance test
【云驻共创】Huawei iConnect使能物联终端一触即联
Redis (IX) - enterprise level solution (II)
Redis (VIII) - enterprise level solution (I)
基于SSM的新闻管理系统
流批一体在京东的探索与实践
Design and principle of tubes responsive data system
[Netease Yunxin] playback demo build: unable to convert parameter 1 from "asyncmodalrunner *" to "std:: nullptr\u T"**
Alexnet of CNN classic network (Theory)
构建基本buildroot文件系统