Unity serialization System Summary-From the Unity Handbook (Script serialization)

Source: Internet
Author: User

First, the summary

in Unity, the serialization of "things" is a very central thing of unity, and many features are built on a serialized system: Like a view panel, a prefab (prefabs), an instantiation (instantiation), a save scene, Load (loading), the thermal reload of the editor code (hotReloading of editor, Code), Unity's own garbage collector ( Resource.GarbageCollectSharedAssets() ). The serialization system is written in C + + for all internal object types (textures, animationclip, Camera, etc).

What are the requirements for a domain that needs to be serialized?

1, public, or private domain with [Serializefield] attribute

2, non-static;

3, the very quantity;

4, not read-only;

5. Other domain types that can be instantiated

Iii. types of domains that can be instantiated

1. Custom non-abstract class with attributes marked with "Serializable"

2, unity4.5 and after the custom structure, and with the "Serializable" tag attribute;

3. A reference to an object derived from Unityengin.object.

4. Basic data type

5. The element field type is an array that can be serialized

6, the element domain type is the list<t> that can be serialized

Iv. issues needing attention.

1. The serialization system does not support the null value of the custom class. If a class has a field in its definition that is marked with the "seriazable" attribute, then it will be added to the null value when serialized, and the new instance needs a new instance, so that it enters a dead loop, in order to limit, Unity supports up to 7 layers. To solve this problem, you can convert this class to serialize a struct that holds the primary members of the class. Let classes that need to serialize such members inherit from the Iserializationcallbackreceiver interface and implement two of its methods. You can refer to the Unity Manual for a good understanding.

2 . The serialization system is not good for polymorphic support. If there is an array, such as an animal array, which holds three instances of subclasses of the inherited automaton class, such as rabbits, dogs, cats,

Then an instance of three animals will be saved in the array after instantiation.

Unity serialization System Summary-From the Unity Handbook (Script serialization)

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.