I am trying to implement an interaction system via an interface but am having trouble figuring out how to call functions in my interface via C++. I am able to call these interface functions in Blueprints with the message nodes.
Some answers online talk about using Execute_* functions but I can’t find any clear description on how to do this. I have tried casting with Cast<>() and InterfaceCast but these cause my project to crash.
Specifically, what I am trying to do is run a trace to see if there are any actors in front of the player pawn that implement my InteractableInterface. And then I want to be able to call the Interact(…) function on that actor. My InteractableInterface code is shown below.
Any help would be appreciated.
Thanks very much
UINTERFACE(meta = (CannotImplementInterfaceInBlueprint))
class UInteractableInterface : public UInterface
{
GENERATED_UINTERFACE_BODY()
};
class IInteractableInterface
{
GENERATED_IINTERFACE_BODY()
public:
UFUNCTION(BlueprintCallable, Category = Interact)
virtual bool IsInteractable()=0;
UFUNCTION(BlueprintCallable, Category = Interact)
virtual void Interact(AKillablePawn* Instigator)=0;
};