I’m writing a plugin that integrates some third party code. It requires me to implement some methods from a pure abstract class but as far as I’ve read and seen, Unreal does not allow multiple inheritance.
This means that I’m ruled out from having a UObject that inherits from UObject and the third party pure abstract class (Let’s call it MyPureAbstractClass). It also seems to rule out wrapping it in a UInterface class as it would need to inherit from UInterface and MyPureAbstractClass.
It’s the other way around - you can multiple inherit just fine, but you’re only allowed a single UObject-derived base. In this case, if you’d tried the obvious solution you initially mentioned, you’d find it works fine:
UCLASS()
class UMyObject: public UObject, public MyPureAbstractClass
{
...
// Implement MyPureAbstractClass method overrides
};
Yeah it appears that if it worked in the past, it doesn’t work now. I end up getting an UnrealHeaderTool error for my class definition:
Missing '{' in 'Class'
I’m going to attempt a slightly messy way of wrapping up the pure abstract class in another class so that wrapper class can get away with just needing to inherit UObject or UInterface. If I succeed I’ll post my solution here soon.
Sorry about the late reply, I had a workaround (Albeit messy) where I encapsulated a class within a class in order to hide the inheritance (Can post code if anyone ever finds it useful).
After looking at the example you provided very carefully, here was an example of the code I had:
UCLASS()
class MYPROJECT_API UUnrealEntity : public UObject, public MyNamespace::MyPureAbstractClass
{
GENERATED_BODY()
public:
// Stuff
};
Compare that to the example class you provided:
UCLASS()
class UPaperTiledImporterFactory : public UFactory, public FReimportHandler
{
GENERATED_UCLASS_BODY()
// Etc, etc
};
**
The third party class that I need to inherit from is not prefixed with an “F”. **
So it looks like the requirement for multiple inheritance to be Unreal classes means that you need to have an external class’ class name prefixed with an “F” (Or more accurately, any class that won’t be looked after by the UObject garbage collector and can be multi-inherited as it’s an Unreal type), which is a little more work on my end. Here’s an example of what I ended up with using a class with a mix of virtual and normal methods (Ignoring pure abstract for now) that compiles, though I haven’t tested it’s use.
class FMyEntityClass : public MyNamespace::MyEntityClass
{
public:
// Stuff
};
UCLASS()
class MYPROJECT_API UUnrealEntity : public UObject, public FMyEntityClass
{
GENERATED_BODY()
public:
// Stuff
};
It’s a a shame that I have to have a class in the middle just to use the right naming convention, but it’s workable.
I suspect it’s the namespacing that UHT is unable to handle, not the prefix - I use multiple inheritance with base classes which don’t follow UE4 naming conventions.
Did you try like this?
using MyNamespace::MyPureAbstractClass;
UCLASS()
class MYPROJECT_API UUnrealEntity : public UObject, public MyPureAbstractClass