{"id":1772,"date":"2020-04-18T08:37:41","date_gmt":"2020-04-18T00:37:41","guid":{"rendered":"http:\/\/blog.coolcoding.cn\/?p=1772"},"modified":"2020-09-27T17:04:53","modified_gmt":"2020-09-27T09:04:53","slug":"unity%e8%a7%a3%e5%86%b3%e9%94%99%e8%af%afa-script-behaviour-has-a-different-serialization-layout-when-loading","status":"publish","type":"post","link":"https:\/\/blog.coolcoding.cn\/?p=1772","title":{"rendered":"[Unity]\u89e3\u51b3\u9519\u8bef:A script behaviour has a different serialization layout when loading"},"content":{"rendered":"\n<p>\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\u78b0\u5230\u4e00\u4e2a\u95ee\u9898,\u52a0\u8f7d\u4e00\u4e2aPrefab, Unity\u4f1a\u62a5\u4ee5\u4e0b\u9519\u8bef:<\/p>\n\n\n\n<p>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?<\/p>\n\n\n\n<p> \u8fd9\u662f\u793a\u4f8b\u4ee3\u7801 <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using UnityEngine;\n \npublic class ObjectPreview : MonoBehaviour \n{\n    #if UNITY_EDITOR\n\tpublic GameObject obj;\n \n\tvoid Start () \n\t{\n\t\t\/\/ code ...\n\t}\n \n    #endif\n}<\/code><\/pre>\n\n\n\n<p>\u4e5f\u5c31\u662f\u8bf4, ObjectPreview\u5728\u7f16\u8f91\u5668\u6a21\u5f0f\u4e0b\u548c\u975e\u7f16\u8f91\u5668\u6a21\u5f0f\u4e0b, \u5e8f\u5217\u5316\u51fa\u6765\u7684\u5185\u5bb9\u662f\u4e0d\u540c\u7684<br>\n\u90a3\u4e48, \u7531\u4e8e\u7f8e\u672f(\u6216\u8005\u5176\u5b83\u56e2\u961f\u6210\u5458)\u505a\u7684Prefab\u662f\u5728\u7f16\u8f91\u5668\u73af\u5883\u4e0b\u4ea7\u751f\u7684, \u6240\u4ee5\u662f\u5e26\u6709obj\u7684\u5e8f\u5217\u5316\u6570\u636e<\/p>\n\n\n\n<p>\u4f46\u662f\u5728\u8fd0\u884c\u65f6, \u7531\u4e8e\u8fd9\u4e2aUNITY_EDITOR\u5b8f,\u5bfc\u81f4\u8fd0\u884c\u65f6\u4e0e\u7f16\u8f91\u5668 \u5e8f\u5217\u5316\u5185\u5bb9\u4e0d\u540c!<\/p>\n\n\n\n<p>\u6b63\u786e\u7684\u505a\u6cd5\u662f\u53bb\u6389 #if UNITY_EDITOR<\/p>\n\n\n\n<p>\u6216\u8005\u628a#if&nbsp;UNITY_EDITOR\u5305\u4f4f\u6574\u4e2a\u7c7b!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\u78b0\u5230\u4e00\u4e2a\u95ee\u9898,\u52a0\u8f7d\u4e00\u4e2aPrefab, Unity\u4f1a\u62a5\u4ee5\u4e0b\u9519\u8bef: A script behaviou [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/1772"}],"collection":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1772"}],"version-history":[{"count":2,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/1772\/revisions"}],"predecessor-version":[{"id":2672,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/1772\/revisions\/2672"}],"wp:attachment":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1772"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1772"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1772"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}