Actually bringing this back up since there are a several areas I need to save that I'm using serialized dictionaries.
I'm now working on saving equipment and are having similar issues except now I'm getting various InvalidCastException: Specified cast is not valid errors.
Here is what I'm trying to do:
ItemDictionary class inherits from the same serializeabledictionary class. Here are the fields on that one. By switching to protected instead of private, I do see the fields in the type window and I was able to create a new type for the ItemDictionary
Code: Select all
[Serializable]
public class SerializableDictionary<TKey, TValue> : Dictionary<TKey, TValue>, ISerializationCallbackReceiver
{
[SerializeField]
protected List<TKey> keys = new List<TKey>();
[SerializeField]
protected List<TValue> values = new List<TValue>();
...
}
Saving produces no errors, but the key and value lists are empty in the save file
Code: Select all
public void SaveData(string FilePath)
{
ES3.Save<ItemDictionary>("equipmentList", items, FilePath);
}
Few extra steps in loading, mainly just specific to my game so can be ignored:
Code: Select all
public void LoadData(string FilePath)
{
if (ES3.KeyExists("equipmentList", FilePath))
{
UnEquipAll();
ItemDictionary savedItems = ES3.Load<ItemDictionary>("equipmentList", FilePath);
foreach (var item in savedItems.Values)
{
if (savedItems != null)
this.EquipItem(item as EquipableItem);
}
}
And then the error:
- EasySaveError.JPG (102.89 KiB) Viewed 2118 times
The ItemDictionary is a dictionary of custom classes. The key is a UISlot class(head, shoulder, legs, etc.) and the value is a scriptableobject item created at design time. Here are the fields related to that object (note the equipment types are all enums:
Code: Select all
[CreateAssetMenu(menuName = "Items/Equippable Item")]
public class EquipableItem : Item
{
[System.Serializable]
public struct EquipmentModifier
{
public BaseStat stat;
public float value;
public StatModType type;
}
[Space]
public EquipmentTier Tier;
public EquipmentSubType EquipType;
public EquipmentType EquipmentType;
public AudioClip equipSFX;
[Space]
public EquipmentModifier[] modifiers;
...
}