You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When deserializing a class, non serialized member fields are set to null, even when it is initialized in default constructor or member initializer. Member fields such as NonSerialized decorator or private members are all set to null.
Is this intended behaviour?
Example code I used is attached.
Thank you.
usingSystem;usingSystem.Collections.Generic;usingUnityEngine;usingTriInspector;usingOdinSerializer;[Serializable]classSerializerTestClass{publicstringmessage="Message initialized in Class";[NonSerialized]publicstringmessage2="NonSerialized message initialized in Class";internalstringmessage3="Private message initialized in Class";publicSerializerTestClass(){methodAction=testMethod;}publicActionaction=()=>{Debug.Log("Action initialized in Class");};publicActionmethodAction=staticTestMethod;publicvoidPrintTest(){Debug.Log(message);Debug.Log(message2);Debug.Log(message3);action();methodAction();}voidtestMethod(){Debug.Log("MethodAction initialized in Class");}staticvoidstaticTestMethod(){Debug.Log("staticTestMethod initialized in Class");}}publicclassSerializerTest:MonoBehaviour{SerializerTestClasstestClass=newSerializerTestClass();voidAwake(){}voidMethodAction(){Debug.Log("MethodAction called");}[Button]voidSerialize(){Debug.Log("=============== Serialize Test =================");Init();vardata=Serialize<SerializerTestClass>(testClass,false);Debug.Log("Serialized Data: "+System.Text.Encoding.UTF8.GetString(data));testClass=Deserialize<SerializerTestClass>(data,false);testClass.PrintTest();}[Button]voidInit(){testClass=new();testClass.message="Message initialized in Constructor";testClass.message2="NonSerialized message initialized in Constructor";testClass.message3="Private message initialized in Constructor";testClass.action=()=>{Debug.Log("Action called");};testClass.methodAction=MethodAction;}publicstaticbyte[]Serialize<T>(inTvalue,boolbinary=true){returnSerializationUtility.SerializeValue(value,binary?DataFormat.Binary:DataFormat.JSON);}publicstaticTDeserialize<T>(byte[]bytes,boolbinary=true){returnSerializationUtility.DeserializeValue<T>(bytes,binary?DataFormat.Binary:DataFormat.JSON);}}
The text was updated successfully, but these errors were encountered:
When deserializing a class, non serialized member fields are set to null, even when it is initialized in default constructor or member initializer. Member fields such as NonSerialized decorator or private members are all set to null.
Is this intended behaviour?
Example code I used is attached.
Thank you.
The text was updated successfully, but these errors were encountered: