Here’s how you can make interfaces.

In you C++ Classes folder, right click and create a new C++ class deriving from the Unreal Interface parent class. As of Ue4 4.22 it is on the bottom of the list.

In the public section of the interface header, you’ll put your interface functions.
You must put the below Macro before the interface functions.

UFUNCTION(BlueprintNativeEvent)

Then you put the function. In my case I wrote:

void OnInteract(AActor* Caller)

Next, you will go to a class that you want to use the interface in, and include the interface like any other header file.

Then you will add the following

,public INTERFACENAME

To your class definition. In example,

class INTERFACES_API AInteractableBase : public AActor, public IInteractInterface

In the public section of your class, add ALL the functions that the interface is using. Below them, you will put their implementations.In example,

UFUNCTION(BlueprintNativeEvent)

void OnInteract(AActor* Caller); 

virtual void OnInteract_Implementation(AActor* Caller);

Define only the “_Implementation”.

void AInteractableBase::OnInteract_Implementation(AActor * Caller)
{
Destroy();
}

Then go to your class which will call the interface. In my case, it’s the First Person Character template. To do an interface call, you need to cast to an object and check if it has the interface. If it does, you can move on to execute it.

For example, you could do a Line Trace to get the actor you’re looking at and break the hit result to get the actor you hit.
From there you could do a cast like so to see if the interface is being implemented.

IInteractInterface* Interface = Cast<IInteractInterface>(Interactable);
if (Interface)
{ 
Interface->Execute_OnInteract(Interactable, this); 
}

So what are we doing here?

  1. We are casting to Class IInteractinterface, which is our interface and the object type is an AActor Interactable, which we got by breaking a hit result from a line trace. We are saving the cast as a reference/pointer. If you are confused about casting and would like to know more, click here to go to my post on casting and its syntax.
  2. The IF statement checks to see if our reference is null.
  3. The Execute_FUNCTION NAME is the interface call. It calls the interface function to the particular actor.

That is it!