- edited description
Unity Serialized Dictionary won't serialize with String, List type of dictionary
Issue #845
new
Hello, I’m not sure if this is even supported but wanted to report in case this is a bug.
Issue is simple, when I have dictionary with String Key, and List of classes as value it won’t save dictionary values. After code recompile or opening/closing editor all values are lost.
Here is example setup.
[System.Serializable]
public class SampleDataHolder
{
public string Data;
}
[System.Serializable]
public class SampleDataHolderDictionary : UnitySerializedDictionary<string, List<SampleDataHolder>> { }
[System.Serializable]
public class DataItems : ScriptableObject
{
public SampleDataHolderDictionary Data = new SampleDataHolderDictionary();
}
So in this case Data dictionary in DataItems won’t save your values.
I have a simple workaround where I can create wrapper class for List, like
[System.Serializable]
public class SampleDataHolder
{
public string Data;
}
[System.Serializable]
public class SampleDataHolderList
{
public List<SampleDataHolder> DataItems = new List<SampleDataHolder>();
}
[System.Serializable]
public class SampleDataHolderDictionary : UnitySerializedDictionary<string, SampleDataHolderList> { }
[System.Serializable]
public class DataItems : ScriptableObject
{
public SampleDataHolderDictionary Data = new SampleDataHolderDictionary();
}
Unity 2020.3.25f1, Windows 10, Editor only is not enabled, Odin 2.1.12.0 (I’ll try upgrading to see if it is fixed, didn’t realize so many versions released :D)
Comments (1)
-
reporter - Log in to comment