Unity-SerializableDictionary
Unity-SerializableDictionary copied to clipboard
Using SerializableDictionary in ScriptableObjects: data loss
trafficstars
Maybe that's me dummy-dumb, but I faced next issue:
- I create scriptableobject that has SerializableDictionary as field
- I fill it with data via inspector (no problems here)
- I reload project and all data of ScriptableObject are lost
[Serializable]
public class StringEventDictionary : SerializableDictionary<string, Event> {}
[CreateAssetMenu(fileName = "New GameEvents Data", menuName = "GameEvents Data", order = 54)]
public class GameEventsData : ScriptableObject
{
[SerializeField]
private StringEventDictionary events = null;
public IDictionary<string, Event> Events
{
get { return events; }
set { events.CopyFrom(value); }
}
}
[Serializable]
public class Event
{
public event Action<int> action;
public void EventRunner(int id)
{
action?.Invoke(id);
}
}
I'm running into that too.
Hi,
Are you using System.Action in the class Event? System.Action cannot be serialized by Unity. I think this is the cause of the data loss.
If I use a type serializable by unity, I don't observe a data loss when used in a ScriptableObject.