Using SerializableDictionary in ScriptableObjects: data loss
Bogenbai opened this issue · 3 comments
Bogenbai commented
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);
}
}
laurentopia commented
I'm running into that too.
azixMcAze commented
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
.
odoluca commented
Facing the same issue still in 2024. Funnily, only one of two SOs of same type loses data. the other is fine. They are literally of instances of same type.