多余的空白符导致shader报错
xxx shader is not supported on this GPU (none of subshaders/fallbacks are suitable)
Both vertex and fragment programs must be present in a shader snippet. Excluding it from compilation.
这个shader在2019.4.18f1不会报错,但是在2021.2.18f1会报上述错误,原因是多了两个不知名空白字符...
The referenced script on this Behaviour (Game Object '<null>') is missing!
这个报错在编辑器中不会出现,而且在编辑器中检查,看不到哪个脚本丢失了,但导出webgl后在浏览器里运行时出现了。最后通过对.prefab文件的文本进行检查,发现其中包含了很多节点并没有任何引用,但这些节点确确实实关联了丢失的脚本。因为节点没有被引用,在编辑器中并不会生成这些节点,所以看不到!这些节点怎么来的已经无法求证了,解决办法就是直接在文本编辑器中修改.prefab文件,删除这些节点。
记一次升级unity版本后场景物体变成全黑色
原版本:5.6.3p4
现版本:2019.4.18f1
现象:场景里所有使用lagacy shader/diffuse
的物体都变成全黑色,这些物体都用到了lightmap
解决:File > Build Settings > Player Settings > Graphics > Shader Stripping,Lightmap Modes改为Custom
,然后点击Import From Current Scene
。
真机上部分shader异常
unity版本:2021.2.18f1
现象:Editor里、webgl、小游戏均表现正常,但是在Redmi K30上,部分材质是一片紫色,因为大部分异常shader都用到了HDR,起初以为是HDR的原因,去掉后发现并没有好。
解决:现在开发机上,Edit > Project Setting > Other Settings > 取消勾选Auto Graphics API for Windows > 添加 OpenGLES3/OpenGLES2/Vulkan等进行测试,发现Vulkan可以复现。接下来修改Android的设置,APIs中去掉Vulkan,重新打包,正常了。
URP报错 You can only call cameraColorTarget inside the scope of a ScriptableRenderPass
旧项目从2021.3.16f1
升级到2022.3.14f1
,遇到下面的报错刷屏
You can only call cameraColorTarget inside the scope of a ScriptableRenderPass. Otherwise the pipeline camera target texture might have not been created or might have already been disposed.
UnityEngine.Rendering.Universal.ScriptableRenderer:get_cameraColorTarget ()
GrabPassRenderFeature:AddRenderPasses (UnityEngine.Rendering.Universal.ScriptableRenderer,UnityEngine.Rendering.Universal.RenderingData&) (at Assets/AssetSources/shader/Fx_Feature/AfterTransparent_Distortion/GrabPassRenderFeature.cs:174)
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
解决方法参考升级手册:
https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@13.1/manual/upgrade-guide-2022-1.html
Insecure connection not allowed
旧项目从2021.3.16f1升级到2022.3.14f1,使用UnityWebRequest访问http地址报错,原因是2022.1.0a5
以后的版本默认不支持http请求,只支持https请求。修改设置:
Edit > Project Settings > Player > Other Settings > Configuration > Allow downloads over HTTP
安卓构建报错:UnityException: Android SDK not found
升级到2022.3.14f1后,打安卓包报错:
UnityException: Android SDK not found
Unable to detect SDK in the selected directory. D:\android-sdk-windows\cmdline-tools\latest\bin\sdkmanager.bat does not exist. Android SDK command-line tools component is not found. Make sure "Command-line Tools (latest)" is installed in the SDK manager.
If command-line tools are installed, but this message is still shown, please restart the Unity editor.
根据指引,在android studio打开sdkmanager,安装command-line tools
安卓构建报错:错误: 加载主类 com.android.sdklib.tool.sdkmanager.SdkManagerCli 时出现 LinkageError
升级到2022.3.14f1后,打安卓包报错:
错误: 加载主类 com.android.sdklib.tool.sdkmanager.SdkManagerCli 时出现 LinkageError
java.lang.UnsupportedClassVersionError: com/android/sdklib/tool/sdkmanager/SdkManagerCli has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0
错误信息很明显,java runtime版本不匹配。
从这里可以看到java jdk version和class file version的对应关系:https://javaalmanac.io/bytecode/versions/
class file version 61.0,对应Java 17,55.0则对应Java 11。
可以从unity官网看到2022.3支持的就是Java 11: https://docs.unity3d.com/Manual/android-sdksetup.html。
再在构建机上确认下java的版本:
C:\Users\clientbuilder>echo %JAVA_HOME%
C:\Program Files\Java\jdk-11.0.17
那61从何而来?从上述unity官网可以看到2022.3对应的command-line tools version:
应该是解决上一个报错时,安装的latest command-line tools导致的,于是将command-line tools修改为6.0
再构一次,上一个报错又出来了:Android NDK not found
代码里一直通过EditorPrefs.SetString("AndroidNdkRoot", xxx)
来设置ndk路径,看起来2022不奏效了。改用AndroidExternalToolsSettings.ndkRootPath
。