unity serialization

What is serialized

  • Serialization unity plays a role in weightlifting light enough to develop unity, many of the core functions are implemented based on serialization and de-serialization. Serialization simple terms is that we want to save the binary data storage, and then when we need to, read binary files, deserialized back. Here are some examples of common sequence:

    • Data storage scripted. We c # code, the data to be stored we may be serialized for storage
    • prefab and initialization. In the unity development process, we will make a lot of preforms (prefab), these prefab are serialized, stored in binary form. When you want to initialize the preform, according to previous Unity new sequence information of an object, information on the object and then deserialized back, clone achieve similar effects.
    • In functional unity expand editor, AssetBundle and so on, you can see the sequence of the figure.
  • Serializable objects

    • Public, or have [SerializeField] property, non-static, amount is, the non-read-only
    • Custom non-abstract class and has properties Serializable
    • Unity.object inherited from class
    • Array and List
    note:
    • Dictionary attributes can not be serialized adding Serializable
    • If a base class can be serialized, then it is added even if the sequence of characteristic can not be serialized
    • Serialization can not save another deserialized object pointer, because new anti-serialization is a new object, a pointer to the memory will not be the original object
  • Serialization class unity can be ScriptableObject editor, when we inherit this base class, we can call our unity to serialize the interface. Specific sequences of interface to the unity of the official document viewing interfaces to use, no specific description here.

  • The following specific Laijiangjiang pit development process personal encounter

    • Firstly, given the information section of the development process
    Serialization depth limit 7 exceeded at 'XNodeScripts::ConfigNode.nodeList'. There may be an object composition cycle in one or more of your serialized classes.
    
    Serialization hierarchy:
    8: XNodeScripts::ConfigNode.nodeList
    7: XNodeScripts::ConfigNode.nodeList
    6: XNodeScripts::ConfigNode.nodeList
    5: XNodeScripts::ConfigNode.nodeList
    4: XNodeScripts::ConfigNode.nodeList
    3: XNodeScripts::ConfigNode.nodeList
    2: XNodeScripts::ConfigNode.nodeList
    1: XNodeScripts::ConfigNode.nodeList
    0: XNodeScripts::SelectMsgNode.rootNode

    The error message prompts us here at nodeList when I create a sequence of data, probably in this nodeList there serialized cycle. Here we find unity also prompt us to serialize a depth of 7. I found on the Internet, that we subsystems are built on top of serialization system, so if left unchecked sequence of its cycle of death, so that when a very large serialized stream will cause the entire system to crash. To avoid such a situation, using a Unity depth threshold value 7, and the cyclic sequence into an empty subset is at most 7. When we created during serialization, a very common mistake is constructed by a sequence of similar data structure tree in our statement serialization class inside, if there contains the object itself, similar to

    [Serializable]
    public class DepthClass : ScriptableObject
    {
        public List<DepthClass> depthObjects; 
    }

    This sequence structure of the appeal, it will have the system shown before I error. Effectively avoid the sequence of null values, for the tree include store the dictionary, I used the List The key storage, the next child node, the string are used to store a key value, and then is stored in all nodes as a List. So we have to find the key nodes through which we can use heap memory or more efficient ways to search, to avoid the bottom of efficiency. There is no thought of a better solution. . . 23333

Guess you like

Origin www.cnblogs.com/fzuljz/p/11168131.html