介绍
项目需要由 Unity 5.6.6f2 升级到 Unity 2020.3.7f1,下面记录主要修复升级的过程。
另外可以参考:
环境
- Unity 5.6.6f2
- Unity 2020.3.7f1
- macOS 10.14.6
- Windows 7
编译错误
Unity 2020 中新增了 Safe Mode,在打开工程时有编译错误会停止导入,直接进入 Safe Mode。
TextMesh Pro
1
|
Library/PackageCache/com.unity.textmeshpro@3.0.4/Scripts/Runtime/TMP_Text.cs(1720,25): warning CS0436: The type 'ShaderUtilities' in 'Library/PackageCache/com.unity.textmeshpro@3.0.4/Scripts/Runtime/TMP_ShaderUtilities.cs' conflicts with the imported type 'ShaderUtilities' in 'TextMeshPro-5.6-Runtime, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'. Using the type defined in 'Library/PackageCache/com.unity.textmeshpro@3.0.4/Scripts/Runtime/TMP_ShaderUtilities.cs'.
|
提示 TextMesh Pro 类重定义,需要先将 PackageManager 中的内置的新版 TextMeshPro 删除掉,只使用项目内部的。
PostProcessing2
1
|
Assets/PostProcessing-2/PostProcessing/Editor/Utils/PostProcessShaderIncludePath.cs(10,10): error CS0619: 'ShaderIncludePathAttribute' is obsolete: '[ShaderIncludePath] attribute is no longer supported. Your shader library must be under the Assets folder or in a package. To include shader headers directly from a package, use #include "Packages/<package name>/<path to your header file>"'
|
PostProcessing-2 需要更新,暂时先将这个脚本使用的属性注释掉。
7zip
1
2
|
Deterministic compilation failed. You can disable Deterministic builds in Player Settings
Assets/Plugins/7zip/Compress/LzmaAlone/Properties/AssemblyInfo.cs(29,28): error CS8357: The specified version string contains wildcards, which are not compatible with determinism. Either remove wildcards from the version string, or disable determinism for this compilation
|
将通配符改为具体数字 0
Assets/Plugins/7zip/Compress/LzmaAlone/Properties/AssemblyInfo.cs
[assembly: AssemblyVersion("4.12.*")]
改为
[assembly: AssemblyVersion("4.12.0")]
iTween Editor
1
|
Assets/Plugins/iTweenEditor/iTween.cs(698,33): error CS0619: 'GUITexture' is obsolete: 'GUITexture has been removed. Use UI.Image instead.'
|
删除用不到的 iTween Editor 插件
编译器参数文件
1
2
|
Using obsolete custom response file 'mcs.rsp'. Please use 'csc.rsp' instead.
UnityEditor.Scripting.ScriptCompilation.EditorCompilationInterface:CompileScriptsNoStop (UnityEditor.Scripting.ScriptCompilation.EditorScriptCompilationOptions,UnityEditor.BuildTargetGroup,UnityEditor.BuildTarget,string[]) (at /Users/bokken/buildslave/unity/build/Editor/Mono/Scripting/ScriptCompilation/EditorCompilationInterface.cs:306)
|
Assets/mcs.rsp
改名为 Assets/csc.rsp
粒子
1
2
3
4
|
error CS0246: The type or namespace name 'Particle' could not be found (are you missing a using directive or an assembly reference?)
error CS0246: The type or namespace name 'ParticleEmitter' could not be found (are you missing a using directive or an assembly reference?)
error CS0246: The type or namespace name 'ParticleAnimator' could not be found (are you missing a using directive or an assembly reference?)
error CS0246: The type or namespace name 'ParticleRenderer' could not be found (are you missing a using directive or an assembly reference?)
|
将所有 ParticleEmitter 替换为 ParticleSystem,注释掉所有出问题的其他地方。
Handles API
1
2
3
|
error CS0117: 'Handles' does not contain a definition for 'ConeCap'
error CS0117: 'Handles' does not contain a definition for 'CylinderCap'
error CS0117: 'Handles' does not contain a definition for 'CubeCap'
|
方法名字改变,额外增加最后一个参数,这里使用 EventType.Repaint
1
2
3
|
case GIZMO_TYPE.POSITION: Handles.ConeHandleCap(0, GetPosition(selTrans) + vecDirect * fLineLen, Quaternion.Euler(vecEuler), fCapSize*1.6f, EventType.Repaint); break;
case GIZMO_TYPE.ROTATION: Handles.CylinderHandleCap(0, GetPosition(selTrans) + vecDirect * fLineLen, Quaternion.Euler(vecEuler), fCapSize*2f, EventType.Repaint); break;
case GIZMO_TYPE.SCALE: Handles.CubeHandleCap(0, GetPosition(selTrans) + vecDirect * fLineLen, Quaternion.Euler(vecEuler), fCapSize, EventType.Repaint); break;
|
命名空间
1
|
error CS0234: The type or namespace name 'ProfilerArea' does not exist in the namespace 'UnityEditorInternal' (are you missing an assembly reference?)
|
修改命名空间
1
2
|
UnityEditorInternal.ProfilerArea.Rendering
UnityEngine.Profiling.ProfilerArea.Rendering
|
Cinema Director
1
2
3
|
Assets/Cinema Suite/Cinema Director/Cutscene Items/Global Items/Transitions/FadeFromBlack.cs(20,4): error CS0619: 'GUITexture' is obsolete: 'GUITexture has been removed. Use UI.Image instead.'
Assets/Cinema Suite/Cinema Director/Cutscene Items/Global Items/Transitions/FadeFromBlack.cs(20,52): error CS0619: 'GUITexture' is obsolete: 'GUITexture has been removed. Use UI.Image instead.'
Assets/Cinema Suite/Cinema Director/Cutscene Items/Global Items/Transitions/FadeFromBlack.cs(23,54): error CS0619: 'GUITexture' is obsolete: 'GUITexture has been removed. Use UI.Image instead.'
|
Cinema Director 编译报错决定使用插件的最新版本 1.6.2.0
SuperSplines Pro
此插件看起来已经不再更新
最新版本 3.0
最新发布日期 2013年6月25日
但是项目依然在用,考虑只做兼容性修复
API 变化
1
2
|
error CS0619: 'ModelImporter.importMaterials' is obsolete: 'importMaterials has been removed. Use materialImportMode instead.'
error CS0029: Cannot implicitly convert type 'UnityEditor.Build.Reporting.BuildReport' to 'string'
|
替换为提示的 API 即可。
导入工程
编译错误修复完毕后 Unity 会自动进行导入资源,导入完成后,将所有修改的 meta 与地形升级文件提交
运行时错误
GUI Layer 废弃
1
2
3
4
|
Component GUI Layer in Main Camera for Scene Assets/Hero/Scene/ui/ThirdPartyUI.unity is no longer available.
It will be removed after you edit this GameObject and save the Scene.
Component at index 2 could not be loaded when loading game object 'Main Camera'. Removing it!
|
API 变化
1
|
error loading module Lua/xxx from CustomLoader, Assets/Lua/xxx.txt:1: unexpected symbol near '<\239>'
|
bytes 不像以前一样会在返回结果中去除 UTF8-BOM,既可以选择去除 Lua 文件中的 UTF8-BOM 头,也可以选择在读取文件时去除 UTF8-BOM 头。
xLua
1
|
LuaException: c# exception:This type must add to CSharpCallLua: XXXXXXXXXX,stack: at XLua.ObjectTranslator.CreateDelegateBridge (System.IntPtr L, System.Type delegateType, System.Int32 idx) [0x001a8] in Assets/XLua/Src/ObjectTranslator.cs:535
|
1、默认配置不生成代码运行会报错
这是因为Api Compatibility Level设置为.NET Standard 2.0,而.NET Standard 2.0不支持emit导致的。
解决方案:平时开发Api Compatibility Level设置为.NET 4.x,就能支持编辑器不生成代码开发。发布手机版本时,按Unity官方的建议,可配置为.NET Standard 2.0,包会更小些。
地图无法加载
1
2
3
4
5
6
7
8
9
10
11
12
|
error! load XML path:xxxxxxxxxxxxx
System.Xml.XmlException: Data at the root level is invalid. Line 1, position 1.
at System.Xml.XmlTextReaderImpl.Throw (System.Exception e) [0x00027] in <0f9699188f0c414ea6fb5557f5c16d15>:0
at System.Xml.XmlTextReaderImpl.Throw (System.String res, System.String arg) [0x00029] in <0f9699188f0c414ea6fb5557f5c16d15>:0
at System.Xml.XmlTextReaderImpl.Throw (System.String res) [0x00000] in <0f9699188f0c414ea6fb5557f5c16d15>:0
at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace () [0x0012c] in <0f9699188f0c414ea6fb5557f5c16d15>:0
at System.Xml.XmlTextReaderImpl.ParseDocumentContent () [0x002d4] in <0f9699188f0c414ea6fb5557f5c16d15>:0
at System.Xml.XmlTextReaderImpl.Read () [0x0008c] in <0f9699188f0c414ea6fb5557f5c16d15>:0
at System.Xml.XmlLoader.Load (System.Xml.XmlDocument doc, System.Xml.XmlReader reader, System.Boolean preserveWhitespace) [0x000a6] in <0f9699188f0c414ea6fb5557f5c16d15>:0
at System.Xml.XmlDocument.Load (System.Xml.XmlReader reader) [0x0002e] in <0f9699188f0c414ea6fb5557f5c16d15>:0
at System.Xml.XmlDocument.LoadXml (System.String xml) [0x00018] in <0f9699188f0c414ea6fb5557f5c16d15>:0
at SG.XmlData.OpenXml (System.String filePath) [0x00048] in Assets/xxxxx.cs:78
|
Assets/xxxxxxxxxxxxx.xml
文件中有 UTF8-BOM 头
在 Windows 下的 Git for Windows 或 macOS 下的终端中执行find Assets/ -type f -name '*.xml' -print0 | xargs -0 unix2dos --remove-bom
导出 xml 的编辑器脚本用的是 XmlDocument.Save
,不需要处理
打包错误
Gradle 打包
Mobile: [Android] Build fails when there are 680 or more files in the Streaming Assets folder (1272592)
临时修复方法
TIANZHIZHI APR 14, 2021 08:05
This is a compatible bug between com.android.tools.build:gradle:3.6.0 and unity 2020, Please do following step to resolve:
1, Edit -> Player Setting -> Publishing Settings, click “Custom Base Gradle Template” blew the Build section.
2, You will find a “Assets\Plugins\Android\baseProjectTemplate.gradle” file was generated, open it by text editor.
3, change
“classpath ‘com.android.tools.build:gradle:3.6.0’"
into
“classpath ‘com.android.tools.build:gradle:3.4.0’"
Build again, and don’t forget to add it to your CVS.
If you get solved and like this solution, please do me a favor to mark a star for this repo:
https://github.com/yasio/yasio
This repo’s author find this solution and he told me.\
CEYLAN12 APR 13, 2021 12:55
I have the same problem with Unity 2020.3.3f1.\
Unity Issue Tracker - [Android] Build fails when there are 680 or more files in the Streaming Assets folder
插件升级
升级插件时推荐遵循的原则:
- 有时候需要对插件进行扩展,不建议直接修改原始文件,而是在单独的目录中新建文件进行扩展修改,这样易于升级插件版本。
- 如果不确定插件中是否有自定义修改,那么需要先找到插件当前的版本,然后与项目中的插件进行比较,找出差异,在导入插件新版本后移植这些差异修改。
- 由于 Unity 内部缓存系统 Bug,会出现资源发生变化时缓存未变化,因此建议在 Unity 中先删除插件旧版本后退出 Unity,再打开 Unity 导入插件新版本,以便规避缓存问题。
如果想保留目标目录内修改的文件,只更新变化的文件,那么需要使用操作系统的合并目录功能。合并目录功能依赖于修改时间,会保留修改时间更靠后的文件和目录。
因此需要在目录内执行以下命令更新修改时间:
1
|
find /path/to/directory -type f | xargs touch
|
Windows 下可以使用 Git for Windows 执行此命令;macOS 直接在终端内执行。
TextMesh Pro 升级
TextMesh Pro 已经被 Unity 收购,并且 TextMesh Pro 不再维护之前的 AssetStore 版本,已经完全集成进了 Unity PackageManager 中。
下载 PackageManager 版本与项目中的 AssetStore 版本对比,发现大量文件的 GUID 发生变化,如果要想正确在项目中使用,必须更新资源引用的 GUID。在这一步走了错误,尝试使用文本替换的方式进行处理,但是实际实施的时候有几个问题:
- Unity 资源引用实际是由 fileID guid type 三部分构成,文本替换时只能查到 guid,替换不全面会出现问题。
- 文本查找替换整个流程全是手动处理,非常麻烦。
TextMesh Pro 虽然在官方文档中并未提及,但是内置了 GUID 迁移工具,可以直接进行资源的引用修改。
新建空白 Unity 工程,添加 TextMesh Pro,将 Packages 目录下的插件拷贝到升级项目中。
迁移工具 Window/TextMeshPro/Project Files GUID Remapping Tool
错误
1
2
3
4
5
6
7
8
9
10
11
12
13
|
DirectoryNotFoundException: Could not find a part of the path "Assets/TextMesh Pro/PackageConversionData.json".
System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO.FileOptions options) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.IO.FileOptions options, System.String msgPath, System.Boolean bFromProxy, System.Boolean useLongPath, System.Boolean checkHost) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
(wrapper remoting-invoke-with-check) System.IO.FileStream..ctor(string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare,int,System.IO.FileOptions,string,bool,bool,bool)
System.IO.StreamReader..ctor (System.String path, System.Text.Encoding encoding, System.Boolean detectEncodingFromByteOrderMarks, System.Int32 bufferSize, System.Boolean checkHost) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
System.IO.StreamReader..ctor (System.String path, System.Text.Encoding encoding, System.Boolean detectEncodingFromByteOrderMarks, System.Int32 bufferSize) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
System.IO.StreamReader..ctor (System.String path, System.Boolean detectEncodingFromByteOrderMarks) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
System.IO.StreamReader..ctor (System.String path) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
(wrapper remoting-invoke-with-check) System.IO.StreamReader..ctor(string)
System.IO.File.ReadAllText (System.String path) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
TMPro.TMP_ProjectConversionUtility+<ScanProjectFiles>d__24.MoveNext () (at Assets/TextMesh Pro/Scripts/Editor/TMP_PackageUtilities.cs:823)
TMPro.EditorUtilities.TMP_EditorCoroutine.EditorUpdate () (at Assets/TextMesh Pro/Scripts/Editor/TMP_EditorCoroutine.cs:86)
UnityEditor.EditorApplication.Internal_CallUpdateFunctions () (at /Users/bokken/buildslave/unity/build/Editor/Mono/EditorApplication.cs:327)
|
修正路径拼接的错误,然后执行迁移
TMPro.EditorUtilities.TMP_EditorUtility.GetPackageFullPath
最后的返回值使用了 +
号,应该使用 Path.Combine 以添加缺失的目录分隔符 /
1
|
if (path != null) return packagePath + path;
|
改为
1
|
if (path != null) return Path.Combine(packagePath, path);
|
xLua
升级 xLua,下载最新版本
将项目内的 Assets/xLua
目录直接删除,然后将压缩包内的新 Assets/xLua
拷贝过来。
xLua 由 v2.1.13 升级到 v2.1.15
xLua 包中的文件是 755,项目原始文件是 644,可以批量改为 644
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
chmod 644 Assets/Plugins/Android.meta
chmod 644 Assets/Plugins/Android/libs.meta
chmod 644 Assets/Plugins/Android/libs/armeabi-v7a.meta
chmod 644 Assets/Plugins/Android/libs/armeabi-v7a/libxlua.so
chmod 644 Assets/Plugins/Android/libs/armeabi-v7a/libxlua.so.meta
chmod 644 Assets/Plugins/Android/libs/x86.meta
chmod 644 Assets/Plugins/Android/libs/x86/libxlua.so
chmod 644 Assets/Plugins/Android/libs/x86/libxlua.so.meta
chmod 644 Assets/Plugins/WSA.meta
chmod 644 Assets/Plugins/WSA/ARM.meta
chmod 644 Assets/Plugins/WSA/ARM/xlua.dll
chmod 644 Assets/Plugins/WSA/ARM/xlua.dll.meta
chmod 644 Assets/Plugins/WSA/x64.meta
chmod 644 Assets/Plugins/WSA/x64/xlua.dll
chmod 644 Assets/Plugins/WSA/x64/xlua.dll.meta
chmod 644 Assets/Plugins/WSA/x86.meta
chmod 644 Assets/Plugins/WSA/x86/xlua.dll
chmod 644 Assets/Plugins/WSA/x86/xlua.dll.meta
chmod 644 Assets/Plugins/WebGL.meta
chmod 644 Assets/Plugins/WebGL/xlua_webgl.cpp
chmod 644 Assets/Plugins/WebGL/xlua_webgl.cpp.meta
chmod 644 Assets/Plugins/iOS.meta
chmod 644 Assets/Plugins/x86.meta
chmod 644 Assets/Plugins/x86/xlua.dll
chmod 644 Assets/Plugins/x86/xlua.dll.meta
chmod 644 Assets/Plugins/x86_64.meta
chmod 644 Assets/Plugins/x86_64/xlua.dll
chmod 644 Assets/Plugins/x86_64/xlua.dll.meta
|
PostProcessing2
使用 PackageManager 中的版本直接替换。
Cinema Director
Cinema Director 编译报错,需要升级到插件的最新版本 v1.6.2.0 最新发布日期 2021年1月19日
Substance
1
2
|
Assets/T4M/Editor/T4MSC.cs(232,2): error CS0619: 'ProceduralMaterial' is obsolete: 'Built-in support for Substance Designer materials has been removed from Unity. To continue using Substance Designer materials, you will need to install Allegorithmic's external importer from the Asset Store.'
Assets/T4M/Editor/T4MSC.cs(233,2): error CS0619: 'ProceduralMaterial' is obsolete: 'Built-in support for Substance Designer materials has been removed from Unity. To continue using Substance Designer materials, you will need to install Allegorithmic's external importer from the Asset Store.'
|
导入 Substance in Unity 插件
导入后报以下错误
1
2
3
4
5
|
Failed to extract Substance.Editor.InspectorSubstanceImporter class of base type UnityEditor.Experimental.AssetImporters.ScriptedImporterEditor when inspecting Assets/Allegorithmic/Plugins/Substance/Substance Engine/Editor/Substance.Editor.dll
UnityEditor.AssemblyHelper:ExtractAllClassesThatAreUserExtendedScripts (string,string[]&,string[]&,string[]&) (at /Users/bokken/buildslave/unity/build/Editor/Mono/AssemblyHelper.cs:320)
Failed to extract Substance.Editor.SubstanceImporter class of base type UnityEditor.Experimental.AssetImporters.ScriptedImporter when inspecting Assets/Allegorithmic/Plugins/Substance/Substance Engine/Editor/Substance.Editor.dll
UnityEditor.AssemblyHelper:ExtractAllClassesThatAreUserExtendedScripts (string,string[]&,string[]&,string[]&) (at /Users/bokken/buildslave/unity/build/Editor/Mono/AssemblyHelper.cs:320)
|
最终还是将相关代码全部注释掉了,Unity 已经移除原生支持,使用插件发现没有对应类的定义。
Is this in 2018.1 beta?
Unity has removed the native substance support. You need to make a conditinal define for 2018.1 + or remove the proceduralMaterial code from the project completely.
Graphy
升级到 版本 v2.1.3 发布日期 2021年4月19日
运行时报错
1
2
3
|
NullReferenceException: Object reference not set to an instance of an object
Tayx.Graphy.Advanced.G_AdvancedData.Update () (at Assets/Plugins/Graphy - Ultimate Stats Monitor/Runtime/Advanced/G_AdvancedData.cs:100)
|
发现是 ADVANCED - Module 上的引用都为空,点击查看 ADVANCED - Module 这个单独的 Prefab 上的引用也是空,但是打开这个单独的 Prefab 发现上面的引用都是正常的,尝试 Reimport 发现有警告:
1
|
Importer(PrefabImporter) generated inconsistent result for asset(guid:8e60b58e9eec36e46ba32caf55a802f4) "Assets/Plugins/Graphy - Ultimate Stats Monitor/Prefab/Internal/ADVANCED - Module.prefab"
|
删除这个 Prefab,重启 Unity,从原始包中拷贝此文件到工程中,再次 Reimport 就正常了。
应该是之前升级插件时直接删除后复制了新版本的,Unity 内部的缓存因此出现问题。
之后再次升级时应该先在 Unity 内部删除插件,重启 Unity 后再导入新版本的插件。
Smart Ui Selection
直接替换升级
升级到 版本 v3.4.0 发布日期 2021年2月22日
IngameDebugConsole
直接替换升级
升级到 版本 v1.4.8 发布日期 2021年4月13日