How to troubleshoot errors: A script behaviour has a different serialization layout when loading

Source: Internet
Author: User
Tags serialization

In actual development encountered a problem, loading a prefab,unity will report the following error:

A script behaviour has a different serialization layout when loading. (Read bytes but expected bytes), Did you #ifdef unity_editor a section of your serialized properties into any of your Scripts?

Here's the code:

Using Unityengine;

public class Objectpreview:monobehaviour 
{
    #if unity_editor public
	gameobject obj;

	void Start () 
	{
		//code ...
	}

    #endif
}
In other words, Objectpreview in editor mode and non-editor mode, the serialized content is different

So, because art (or other team members) do prefab in an editor environment, it's serialized data with obj.

At runtime, however, this unity_editor macro causes the runtime to be different from the editor serialization.

The right thing to do is to remove the #if unity_editor or wrap the #if unity_editor the entire class.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.