In the Scripting API docs, there doesn’t appear to be any restrictions on using a System.Object field with the SerializeReference attribute:
[SerializeReference]
public object AnySerializableClass = new MySerializableClass(); // should show property field for MySerializableClass
Additionally, I don’t see any restrictions in docs for setting the value to a primitive class type:
[SerializeReference]
public IComparable PrimitiveComparable = "helloThere"; // should show a TextField in editor
[SerializeReference]
public IComparable CustomComparable = new MySerializableComparable(); // shows a PropertyField for MySerializableComparable()
I can sympathize why string values aren’t serialized on a SerializeReference property. System.String isn’t marked with [Serializable]. However, strings are serializable by Unity and they aren’t derived from UnityEngine.Object.
I’m working on a build-time dependency injection framework. My use-case is serializing default values for a given type. To workaround this limitation, I’m using JSON serialization.