Unity升级引擎版本后,项目报错:script class layout is incompatible between the editor and the player
问题如何出现
报错信息在标题已经贴出来了,这里讲下我突然遇到这个问题的原因。
之前使用的是Unity2022的一个老版本,为了使用Unity最新的一些特性支持,我升级到Unity2022.3.61f1c1的新版本。紧接着在其他都没有更改的情况下,我这个项目的自动化构建就失败了,构建日志报错就是:script class layout is incompatible between the editor and the player。
问题如何解决
首先还是搜索网上资料吧,但其实没有什么有用的信息。比如有的人说过几天自动好了,有的人说重装Unity的,反正看着就有点懵,感觉不是解决的路子。比如下面这些相关资料:
https://discussions.unity.com/t/script-class-layout-is-incompatible-between-the-editor-and-the-player/493612/9
https://github.com/SaladLab/Unity3D.IncrementalCompiler/issues/21
https://issuetracker.unity3d.com/issues/error-building-player-because-script-class-layout-is-incompatible-between-the-editor-and-the-player-dot-error-when-trying-to-build-on-webgl
没有什么太多信息的时候,肯定要亲手打开Unity项目看一看吧。奇妙的就是,打开之后,没有任何报错。我在引擎中手动去构建APK,也没有遇到问题。
最后还是回到这个报错的信息上,提示的是C#脚本在 editor and player 上的差异