How can I have a class that inherits the UnityEngine.Object baseclass

I know it’s possible so please don’t say it’s “impossible” because meshes, sprites, materials, etc can do it. Don’t ask why I need to, just answer the question, please, I’m pulling my hair out about this and I can’t find any documentation on it.

No, you can not and should not derive any class from UnityEngine.Object. It’s just a base class wrapper for Unity’s internal native classes. You can derive your own class indirectly from UnityEngine.Object by using either ScriptableObject or MonoBehaviour as base class. Both are derived from UnityEngine.Object and represent a component that is defined on the managed / mono side.

UnityEngine.Object instances require a native counterpart, otherwise they can not be handled by the engine (Keep in mind that Unity is written in C++, not C#). If you derive your own class from UnityEngine.Object or if you create such an instance with “new”, it will not have a native counterpart. This means the object will pretend it is null when you compare it to null. Also Unity can’t really handle the class on the native side where the serialization happens.

So for a custom Mesh class you should use ScriptableObject as base class. It’s the base for many other internal editor classes as well. For example EditorWindow and Editor are also ScriptableObjects.

Just keep in mind to create instances with CreateInstance.

Note that the golden rule to never create such objects with “new” has a few exceptions. Namely the Mesh class as well as the GameObject class. Actually the same rules apply to those behind the scenes. However the managed classes do create the native part from inside the managed constructor. Richard Fine (Unity empolyee) even mentioned in his ScriptableObject talk that he doesn’t know why they didn’t do this for ScriptableObject as well.

Note that the only purpose of the UnityEngine.Object is to provide the native object binding, nothing else. See for yourself. Also here’s the GameObject constructor and here’s the Mesh class constructor.

Custom classes have to be derived from ScriptableObject or MonoBehaviour, at least when you want them to be serialized as assets.