I’m rather confused on how to utilize interfaces in CPP. The wiki gives goes pretty in-depth but for some reason does not include how to call interface functions.
IInteractableInterface.h
public:
UFUNCTION(BlueprintNativeEvent, BlueprintCallable)
void OnInteract();
};
GunBase.h
virtual void OnInteract_Implementation() override;
GunBase.cpp
void AGunBase::OnInteract_Implementation()
{
IInteractableInterface::OnInteract_Implementation();
GetWorld()->RemoveActor(this, true);
UE_LOG(LogTemp, Warning, TEXT("INTERACTED W/ GUN"));
}
Character.cpp
if (Hit.GetActor()!=nullptr && Hit.GetActor()->Implements<UInteractableInterface>())
{
IInteractableInterface* IntFace = Cast<IInteractableInterface>(Hit.GetActor());
IntFace->Execute_OnInteract(Hit.GetActor());
UE_LOG(LogTemp, Warning, TEXT("Actor %s"), *Hit.GetActor()->GetName());
}
And running the game and interacting with the gun results in this log message
LogTemp: Warning: Actor BP_SMG01_C_UAID_00D861193EC68E6501_2092153807
Which tells me that interact is running the line trace and returning the result of the Gun, which does implement the interface, but does not call the Gun’s OnInteract function. What am I doing wrong exactly?