我们的项目是使用C#做为开发语言
在实际开发中碰到一个问题,加载一个Prefab, Unity会报以下错误:
A script behaviour has a different serialization layout when loading. (Read 24 bytes but expected 40 bytes), Did you #ifdef UNITY_EDITOR a section of your serialized properties in any of your scripts?
这是示例代码
using UnityEngine;
public class AkAndroidSettings : AkWwiseInitializationSettings.PlatformSettings
{
#if UNITY_EDITOR
[UnityEditor.InitializeOnLoadMethod]
private static void AutomaticPlatformRegistration()
{
RegisterPlatformSettingsClass<AkAndroidSettings>("Android");
}
#endif // UNITY_EDITOR
}
也就是说, ObjectPreview在编辑器模式下和非编辑器模式下, 序列化出来的内容是不同的
那么, 由于美术(或者其它团队成员)做的Prefab是在编辑器环境下产生的, 所以是带有obj的序列化数据
但是在运行时, 由于这个UNITY_EDITOR宏,导致运行时与编辑器 序列化内容不同!
正确的做法是去掉 #if UNITY_EDITOR
或者把#if UNITY_EDITOR包住整个类!
————————————————
版权声明:本文为CSDN博主「奋斗的老刘」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/u011355822/article/details/46551211