Problem with inherit:

I everyone.
When I try to inherit it’s like if editor don’t detect the class (sure that’s the appearence, probably I fail somewhere) but I can’t find the mistake. Here is the code:

#pragma once

#include "GameFramework/Character.h"
#include "RPGCharacter.generated.h"

UCLASS()
class RPG_API ARPGCharacter : public ACharacter, IControllableCharacter  //Here the mistake
{
	GENERATED_BODY()
    
    ARPGCharacter(const class FObjectInitializer& FObjectInitializer);

public:

    virtual void MoveVertical (float Value);
    virtual void MoveHorizontal (float Value);

};

XCode tell me “Expected class name” and mark the IControllableCharacter.
Here is the definition of IControllableCharacter:

#pragma once

#include "Object.h"
#include "ControllableCharacter.generated.h"

UINTERFACE()
class RPG_API UControllableCharacter : public UInterface
{
    GENERATED_UINTERFACE_BODY()
};





class RPG_API IControllableCharacter
{
public:
    
    GENERATED_IINTERFACE_BODY()
    

    virtual void MoveVertical(float Value);
    virtual void MoveHorizontal(float Value);
};

If you need to see more code (to find the mistake) here is a link to the proyect in Github:
link text

Sorry if the question is very simple, I’m starting now with Unreal Engine, in fact, I’m following a book for this proyect but it must be a mistake because I have exactly the same code than the book.
And the other little problem is the next, the book use this code:

InputComponent = ConstructObject<UInputComponent>(UInputComponent::StaticClass(), this, TEXT("PC_InputComponent0"));

And it’s deprecated and I must use the method “NewObject()”, but, how is the equivalent with that new method?
Thanks so much for your time and your help.

Try adding ‘public’ before the IControllableCharacter:

class RPG_API ARPGCharacter : public ACharacter, public IControllableCharacter

and if you’re trying to create teh input componenet in the constructor, try:

ObjectInitializer.CreateDefaultSubobject<UInputComponent>(this, TEXT("PC_InputComponent0"));

Also, in your IControllableCharacter you’ll need to define it as

  UFUNCTION(BlueprintNativeEvent, BlueprintCallable)
void MoveVertical(float Value);

if you want to access it through blueprints and also in your RPGCharacter.h you need to define the functions like

void MoveVertical_Implementation(float Value);

Firstly I had the public aclarations but it doesn’t work (the same problem).
The UFUNCTION you say , I don’t need it (now) because I’ll use c++ and, I’m not sure but I think this macro is for blueprint no??
And for the input component (the book) don’t use the constructor, it use a method, here is.
The header (.h) :

#pragma once

#include "GameFramework/PlayerController.h"
#include "RPGPlayerController.generated.h"

/**
 *
 */
UCLASS()
class RPG_API ARPGPlayerController : public APlayerController
{
    GENERATED_BODY()
    
protected:
    void MoveVertical(float Value);
    void MoveHorizontal(float Value);
    virtual void SetupInputComponent() override;
    
    
};

And here the .cpp :
#include “RPG.h”
#include “RPGPlayerController.h”
#include “ControllableCharacter.h”

void ARPGPlayerController::MoveVertical (float Value)
{
    IControllableCharacter* pawn = Cast<IControllableCharacter>(GetPawn());
    if (pawn != NULL)
    {
        pawn->MoveVertical(Value);
    }
}

void ARPGPlayerController::MoveHorizontal (float Value)
{
    IControllableCharacter* pawn = Cast<IControllableCharacter>(GetPawn());
    if (pawn != NULL)
    {
        pawn->MoveHorizontal(Value);
    }
}

void ARPGPlayerController::SetupInputComponent()
{
    if (InputComponent == NULL)
    {
        InputComponent = ConstructObject<UInputComponent>(UInputComponent::StaticClass(), this, TEXT("PC_InputComponent0"));
        InputComponent->RegisterComponent();
    }
    
    InputComponent->BindAxis("MoveVertical", this, &ARPGPlayerController::MoveVertical);
    InputComponent->BindAxis("MoveHorizontal", this, &ARPGPlayerController::MoveHorizontal);
    
    this->bShowMouseCursor = true;
}

In that case, what is the equivalence?
Thanks a lot for your faster answer.

OK, I think we are on the same page now.

I think you are mixing implementations. If you are using the interface in a purely c++ implementation, you can do this without having to expose them to blueprints. But I think you’d still need to use

IInterface::Execute_MethodName(ObjectToCallOn);

Does the project compile at this point? I can really on go off what I have been able to do, I don’t have a lot of theoretical knowlege on this. I have tons of interfaces implemented and all are accessible through blueprint as well as code. Additionally, you still need to use ‘public’ to access the public members of the interface. You might need to check and include the interface’s header file.

For the input component try:

InputComponent = NewObject<UInputComponent>(this, TEXT("PC_InputComponent0"));

Is it not compiling or not creating the object

If it says that it expects a class name it simply means that your IControllableCharacter has not been recognized as a class when parsing your header file. Did you forget an include? Try including IControllableCharacter in your header file

That’s error show when I include the header (ControllableCharacter.h).

#pragma once

#include "GameFramework/Character.h"
#include "RPGCharacter.generated.h"
#include "ControllableCharacter.h"

UCLASS()    //Error: Unknown type name 'RPG_SOURCE_ControllableCharacter_h_9_PROLOG'
class RPG_API ARPGCharacter : public ACharacter, public IControllableCharacter  //Error: Expected unqualified-id
{
	GENERATED_BODY()
    
    ARPGCharacter(const class FObjectInitializer& FObjectInitializer);

public:

    virtual void MoveVertical (float Value);
    virtual void MoveHorizontal (float Value);
	
};

I answer myself, I must write the include before the RPGCharacter.generated.h.
Thanks so much, all work fine!

Yes, the XXX.generated.h must always be last :slight_smile:

I will just answer the fix to your error, since the other question is not related to inheritance.

Your error message basically tells you that the compiler could not recognize the class as a class. In other words: It does not see its class definition. Simply include the respective header file appropriately.

As you already noticed, the include must happen before the XXX.generated.h, which always has to come last.