Below is my interface I created for interaction. It was one of the first things I did in my project and I verified it worked with blueprints before merging to GitHub. I got done with another system that uses says interface in C++. That works but the blueprint interactions are now not reacting. The call stack sees the reacting objects from BP as null in C++.
I don’t know what went wrong. I checked my class modifiers. I deleted and regenerated the temp project files “Saved, Intermediate,…etc.”. No change. I’m hoping that maybe I’m just missing something.
#pragma once
#include "CoreMinimal.h"
#include "UObject/Interface.h"
#include "AMyCharacter.h"
#include "IntertactionInterface.generated.h"
// This class does not need to be modified.
UINTERFACE(Blueprintable)
class UIntertactionInterface : public UInterface
{
GENERATED_BODY()
};
/**
*
*/
class DUKEBARTOP_API IIntertactionInterface
{
GENERATED_BODY()
// Add interface functions to this class. This is the class that will be inherited to implement this interface.
public:
/** Reaction to Interact command by a Player */
UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category = Interaction)
void OnInteract(AMyCharacter* BartopCharacter);
};
This is the implementation in the character of the interface
void AMyCharacter::Interact(const FInputActionValue& Value)
{
bool isInteracting = Value.Get<bool>();
if (isInteracting && Controller != nullptr)
{
FHitResult OutHit;
FVector StartLocation = FirstPersonCameraComponent->GetComponentLocation();
FVector EndLocation = StartLocation + FirstPersonCameraComponent->GetForwardVector() * 1000;
const FName TraceTag("InteractTag");
FCollisionQueryParams CollisionParams;
CollisionParams.TraceTag = TraceTag;
GetWorld()->DebugDrawTraceTag = TraceTag;
//GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::White, TEXT("This message will appear on the screen!"));
bool isHit = GetWorld()->LineTraceSingleByChannel
(
OutHit,
StartLocation,
EndLocation,
ECC_Visibility,
CollisionParams
);
if (isHit)
{
AActor* HitActor = OutHit.GetActor();
IIntertactionInterface* ReactingActor = Cast<IIntertactionInterface>(HitActor);
if (ReactingActor)
{
ReactingActor->Execute_OnInteract(HitActor, this);
}
}
}
}