I have created an abstract class inheriting from the AssetPostprocessor
base class, which has some utility methods I intend to have available for concrete implementations:
public abstract class MyAbstractAssetPostprocessor : AssetPostprocessor
{
protected MyAbstractAssetPostprocessor() { ... }
}
I receive an error when the scene loads:
MyAbstractAssetPostprocessor requires a default constructor to be used as an asset post processor
UnityEditor.AssetPostprocessingInternal:GetMeshProcessorVersions()
This probably tells me Unity recognizes the class as an asset processor and wants to instantiate it, but this is obviously absurd as the class is abstract. Is there a way to prevent Unity from showing that error, and should this prevent me from using this class as a base of concrete post-processors?
There’s no real solution i think. Unity automatically searches for all classes derived from AssetPostprocessor and instantiates them into the internal postprocessor list.
What you can try is making your abstract class a generic class. Though i’m not sure if that will prevent Unity from trying to instantiating it. Also i’m not sure if Unity will actually detect classes derived from your abstract class as valid postprocessor. That depends on how Unity actually finds the classes.
You can always use a normal base class and make your abstract members virtual. Keep in mind that when this actually works for the child classes, that the base class will also be instantiated as post processor.
Probably a better approach would be to implement one single PostProcessor that in turn searches for your own post processor mechanics. You could define an interface for all interactions between your framework and the actual postprocessor. Your abstract base class would not be derived from AssetPostprocessor but simply implement your interface. That way the actual postprocessor can use any class that implements that interface.
Of course you have to find your own way to instantiate your actual concrete post processors. You could define an attribute which you have to attach to an actual post processing class and search through all classes and find those which have this attribute.