#pragma once
#include "TargetInterface.generated.h"
UINTERFACE(MinimalAPI)
class UTargetInterface :
public UInterface
{
GENERATED_UINTERFACE_BODY()
};
class ITargetInterface{
GENERATED_IINTERFACE_BODY()
public:
UFUNCTION(BlueprintImplementableEvent, meta=(FriendlyName = "On Interact"))
void OnInteract();
}
It compiles fine and I can access the event in my blueprints but it will always throw an error when I call OnInteract(). It works fine if I put the BlueprintImplementableEvent in a normal class.
Solution:
For some reason you are not allowed to call the function directly if implemented via an interface.
Instead do this (Note: First function argument is the Actor the Interface is casted from. Followed by all normal function args you want to send.):
A quicker way of doing this, without the need for an explicit cast, is to use the static helper function we automatically generate with interfaces. In your example, assuming that your interface is called “ITargetInterface”, you could simply call:
ITargetInterface::Execute_MyFunction(Actor);
which does the cast, and conditional call in one handy function!