Am I going crazy or are long values not serialized (C#)? How come?
Oh wow, I found out that Int16 and Int32 serialize fine. But no luck on long or Int64
Is this by design?
Am I going crazy or are long values not serialized (C#)? How come?
Oh wow, I found out that Int16 and Int32 serialize fine. But no luck on long or Int64
Is this by design?
I’ve never had problems serializing longs. What are you serializing them to? Did you mark them serializable? What does your class look like, and how are you serializing?
How strange. My class looks like this:
[System.Serializable]
public class LocalizedStringDefs
{
//The ID/name of the IULabel to use this definition on
public string m_UILabelName = String.Empty;
//The file the string belongs to
public TextAsset m_xmlSourceFile = null;
//The actual string in the file we want to display
public Int32 m_selectedStringGUID = -1;
//Or true for any random string in the file
public bool m_selectRandom = false;
}
If I make the m_selectedStringGUID a long or an Int64 the serialization of that variable in the Inspector Window will not work.
I think I am experiencing this same thing? Originally I was trying to serialize a System.DateTime then when that didnt appear to work I tried converting it to a long. Still does not seem to serialize.
It seems the problem should be solved in the latest Unity version. It looks like the problem wasn’t the serialization system but rather the lack of long support in the IMGUI and inspector system. The SerializedProperty class does have a longValue. It can be used when the property type is “Integer”. However the default inspector GUI only has an “IntField” that works with “int”, not long. In the past (at least up to Unity 5.6.1f1) there was no “LongField”. If i look at the implementation of “DefaultPropertyField” inside the UnityEditor assembly it uses an IntField. Though if we look up the current decompiled reference source we can see that an Integer property now uses the LongField. So longs should be displayed properly in the inspector.
I’m not sure when they implemented the LongField and changed the default inspector behaviour but it has to be somewhere in between 5.6.1f1 and now ^^.
If you’re stuck with an older Unity version you may want to create a PropertyDrawer and implement your own LongField version. Since it’s just editor code that you use for yourself it would be fine to adapt Unity’s current implementation of the LongField.
I seem to have the same issue with Unity 5.6.6, has anyone had better luck ?