Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using SerializableDictionary in ScriptableObjects: data loss #16

Open
Bogenbai opened this issue Apr 11, 2020 · 3 comments
Open

Using SerializableDictionary in ScriptableObjects: data loss #16

Bogenbai opened this issue Apr 11, 2020 · 3 comments

Comments

@Bogenbai
Copy link

Maybe that's me dummy-dumb, but I faced next issue:

  1. I create scriptableobject that has SerializableDictionary as field
  2. I fill it with data via inspector (no problems here)
  3. 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
Copy link

I'm running into that too.

@azixMcAze
Copy link
Owner

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
Copy link

odoluca commented Jul 30, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants