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:
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.
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”
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.
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
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.