- Home /
Why can't Unity serialize a class defined as: public class SerializableKeyValuePair (T1,T2)?
My class defined as:
[Serializable]
public class SerializableKeyValuePair<T1,T2> {
public T1 Key;
public T2 Value;
}
is not serialized by Unity. Why is that? I was thinking it was the type variables, but Unity can serialize List just fine. All I want is to be able to have an array of these badboys be visible in the editor. Could I do this with editor scripting magic maybe? Or is there some other way?
Answer by Glurth · Aug 17, 2017 at 10:35 PM
public class SerializableKeyValuePair< T1, T2 > { ... } //not serializable by unity
[Serializable]
public class MyStringIntPairs:SerializableKeyValuePair< string, int >{} //non-generic class- serilizable by unity
Hmm, that's a workaround I think I could live with , thanks! You $$anonymous$$d turning this into an answer?
Answer by Bunny83 · Aug 17, 2017 at 06:31 PM
The unity serializer doesn't support classes with generic parameters. The List class is a specific exception. It is the only generic class that is supported. It's actually serialized as array.
Allright, thanks for the input! No workaround that springs to $$anonymous$$d I guess?
Your answer
Follow this Question
Related Questions
[JS] [Editor] SerializedObject from a custom class. 0 Answers
Help with Missing Monobehaviours and Asset Serialization? 0 Answers
Private list is serialized inside a prefab 0 Answers
Editor Serialization of Collections/Collection Interfaces 1 Answer
GameObject HideFlags.DontSave not working as expected 1 Answer