Not out of the box, no, but you could make a “ClassReference” class, and a custom editor for those. However, you would have to decide how to display them, how to search for them, and how to ensure you aren’t just referring to any old random class but only ones that comply (say, by interface or base class). They’d likely be serialized by their name, and what happens if you rename a class after your ClassReference contains an older name? Lots of things to consider there.
Edit: It looks like spiney199 is talking about serializing whole instances of a class, while I am talking about whole classes. It’s always important to distinguish between the two.
As in if they wanted a base class with derived types, then SerializeReference is required to handle the polymorphic serialisation.
But they would need a custom inspector as Unity doesn’t have built in support for this (as far as selecting sub-types, but it can render fields that already have an reference).
No, I meant a Unity wrapper for System.Type along the lines of this:
[Serializable] public class ClassReference
{
public string fullyQualifiedTypeName;
private System.Type type;
private System.Type mustInherit;
//...
}
with all the custom drawer code that would let you browse. Actually making instances of the type would be left as an exercise for the reader. Then you can have a list of “skill classes” with no instances, and when you earn the skill you instantiate state for it in the appropriate manner.
That’s definitely an idea. Though, [SerializeReference] can serialize from a System.Object type field, so I think that would be a substantially less flaky approach.
2023 and beyond also allows SerializeReference on generic types. So this would make for something that would actually workout of the box with no editor work required:
[System.Serializable]
public class ClassReference<T> where T : class, new()
{
[SerializeReference]
private T _reference = new T();
public T Reference => _reference;
}