- Home /
Saving System.DateTime in a Serialized Scriptable Object is defaulting
Hey there! I have a Serializable Class called SaveFile with a System.DateTime field in it. However when I load the Scriptable Object with the SaveFile Class in it all the System.DateTime fields default to January 1st, 0001, Midnight. Is there a way to keep the fields as System.DateTime rather than saving it as a value type and converting back and forth?
Any help would be great! Thanks! Thanks!
EDIT Also wanted to mention that way to save the timestamp is to use a 'long' and get the Ticks property from the DateTime struct.
long myTimeStamp = System.DateTime.Now.Ticks;
Then when you want to use DateTime functionality:
new System.DateTime(myTimeStamp);
Answer by Bunny83 · Sep 19, 2016 at 12:20 AM
Unity can't serialize DateTime values. Have a look at script serialization. There's a list of types Unity can serialize. You can implement the "ISerializationCallbackReceiver" interface as shown in the manual and serialize the DateTime value to a value that Unity can serialize.