Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

long not serialized

Discussion in 'Editor & General Support' started by fwalker, Jun 11, 2013.

  1. fwalker

    fwalker

    Joined:
    Feb 5, 2013
    Posts:
    250
    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?
     
    Last edited: Jun 11, 2013
  2. Jaimi

    Jaimi

    Joined:
    Jan 10, 2009
    Posts:
    6,171
    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?
     
  3. fwalker

    fwalker

    Joined:
    Feb 5, 2013
    Posts:
    250
    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.
     
  4. Alturis2

    Alturis2

    Joined:
    Dec 4, 2013
    Posts:
    38
    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.
     
  5. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,539
    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.
     
  6. Ziggy90

    Ziggy90

    Joined:
    Mar 15, 2017
    Posts:
    6
    I seem to have the same issue with Unity 5.6.6, has anyone had better luck ?