Hello! I’ve been struggling with this for many hours already and it looks like I’m folding :mad: I’ve been trying to follow both the Rama wiki tutorial and the official Epic docs entry for interfaces.
I’m trying to create a C++ Interface for my interactables, here is the .h where it’s declared:
#pragma once
#include "Engine/Engine.h"
#include "InteractInterface.generated.h"
UINTERFACE(Blueprintable)
class UInteractInterface : public UInterface
{
GENERATED_BODY()
};
class IInteractInterface
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable, BlueprintImplementableEvent, Category="Interact")
bool OnPlayerLookAt();
};
I have nothing in the .cpp (maybe that’s the issue).
This is what I have in the interact object.h (under public):
bool OnPlayerLookAt_Implementation();
and in the interact object.cpp (under public as well):
bool APickup::OnPlayerLookAt_Implementation()
{
return false;
}
and here is where I call it:
IInteractInterface* InteractObject = Cast<IInteractInterface>(ActorRef);
if (InteractObject)
{
Cast<IInteractInterface>(InteractObject)->Execute_OnPlayerLookAt(Cast<UObject>(InteractObject));
IInteractInterface::Execute_OnPlayerLookAt(ActorRef);
}
Yes, I’m calling it twice, that’s just me trying to get it to work… The code definitely gets to where it’s supposed to be, because I also tried calling APickup::OnPlayerLookAt_Implementation() directly and it did what it was supposed to. The issue is definitely interface-related, and I have no idea what it is. I tried changing the function declaration in the .h to “virtual ----- override” but it just gives me an error about how there’s nothing to override. If I leave it with virtual and no override it compiles but same result.
I also tried to write a basic declaration in the .cpp of the interface for the function but it claimed it was already defined in the .obj and that it ignored the second definition. I then tried adding “virtual ----- override” and it said that BlueprintImplementable functions couldn’t be virtual. So then I stripped it from any blueprint capabilities and tried compiling again. THEN it complained that the function didn’t override any base class methods.
Thanks for any help and sorry for the nature of this request