I’m trying to extend a class from ACharacter and another own character class to add some attributes and methods to it.
UCLASS()
class TRIBES_API ANPC : public ACharacter , public gurps::Character
{
GENERATED_UCLASS_BODY()
UPROPERTY(EditAnywhere, Category = Behavior)
class UBehaviorTree *NPCBehavior;
};
The compilation fails with "error: IN NPC: Missing ‘{’ in ‘Class’. Does someone have an idea what is going on ?
When i comment the “, public gurps::Character” out it compiles just fine. Also if i extend a non UClass with my own character class it works fine, so the class itself shouldn’t contain any errors.
UCLASS classes can not have multiple inherited classes, except for interfaces. So each UCLASS can only have one direct inherited class and as many interfaces (UINTERFACE) classes as you want.
Thank you! The 2nd class i want to inherit from is from an external library, i guess it is not possible then to extend it since i cannot add additional code to it ?
Btw, this pattern is called “Composition”. It helps to reduce dependency betweed different classes. And it is a good practice to use composition instead of inheritance in most cases. Base classes that will support inheritance should be writed very carefully and follow SOLID as much as possible.
Maybe something has changed since 2014. You can derive your UCLASS from multiple classes if only one is itself a UCLASS. The others can be interfaces or regular classes that are not derived from UE4 classes. For example:
class MyStandardCPPClass : public WhateverIfNecessary
{
//...
}
UCLASS()
class MY_API AMyActor : public AActor, public MyStandardCPPClass
{
GENERATED_BODY()
// ...
}