Download

How do I trigger an Interface Function of a Blueprint from a C++ class?

I’ve gotten it this far…
a5e87ef3c5b39dc9bdee6e795c11c0bf7591b871.jpeg
785242f2a3aee2f77579bd1306026e17e1c826bb.png


void APortsmouthCharacter::Interact()
{
	APlayerController* PController = GetWorld()->GetFirstPlayerController();
	FHitResult InteractHit;
	FString Debug = "Interact Event Pressed";
	UKismetSystemLibrary::PrintString(GetWorld(), Debug, true, false, FLinearColor((1.0f), (0.0f), (0.0f), (1.0f)), (3.0f));
	// Line Trace to see what Object the Player is looking at
	APortsmouthCharacter::TraceForward(PController, InteractHit, InteractDistance);
	if (InteractHit.Actor != NULL) 
	{
		const AActor* InActor = InteractHit.GetActor();
		FString DebugActor = (InActor != NULL) ? InActor->GetName() : FString(TEXT("None"));
		UKismetSystemLibrary::PrintString(GetWorld(), DebugActor, true, false, FLinearColor((1.0f), (1.0f), (0.0f), (1.0f)), (3.0f));
		if (InActor->GetActorClass()->ImplementsInterface(UInteractInterface::StaticClass())) 
		{
			FString DebugTest = "Actor Implements Interact Interface";
			UKismetSystemLibrary::PrintString(GetWorld(), DebugTest, true, false, FLinearColor((1.0f), (0.0f), (0.0f), (1.0f)), (3.0f));
		}
	}
}

I figured it out… with a little help from these Youtube videos:

and this line of code is what made everything work


IInteractInterface::Execute_Interact(InActor);

I also had to remove the const from AActor* InActor