I have tried for hours to create a damage interface that i can call, but it doesn’t call the override function.
UINTERFACE(MinimalAPI)
class UDamageInterface : public UInterface
{
GENERATED_BODY()
};
/**
*
*/
class Test_API IDamageInterface
{
GENERATED_BODY()
// Add interface functions to this class. This is the class that will be inherited to implement this interface.
public:
/** React to a trigger volume activating this object. Return true if the reaction succeeds. */
UFUNCTION(BlueprintNativeEvent, Category = "Trigger Reaction")
void Damage(int _damage);
};
I call the interface in this function
void TestProjectile::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
{
// Only add impulse and destroy projectile if we hit a physics
if ((OtherActor != NULL) && (OtherActor != this) && (OtherComp != NULL) && OtherComp->IsSimulatingPhysics())
{
OtherComp->AddImpulseAtLocation(GetVelocity() * 100.0f, GetActorLocation());
Destroy();
}
if (OtherActor->GetClass()->ImplementsInterface(UDamageInterface::StaticClass()))
{
UE_LOG(LogTemp, Warning, TEXT("In here"));
IDamageInterface::Execute_Damage(OtherActor,5);
Destroy();
}
}
And is used in this class
UCLASS()
class Test_API ANPC : public ACharacter, public IDamageInterface
{
GENERATED_BODY()
public:
// Sets default values for this character's properties
ANPC();
UPROPERTY(EditAnywhere)
AActor* Player;
UPROPERTY(EditAnywhere)
AWaypointHandler* WaypointHandlr;
UPROPERTY(EditAnywhere)
float FMinDistance;
/** React to a trigger volume activating this object. Return true if the reaction succeeds. */
UFUNCTION(BlueprintCallable, BlueprintImplementableEvent, Category = "Trigger Reaction")
void Damage(int _damage);
virtual void Damage_Implementation(int _damage)override;
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
UFUNCTION(BlueprintNativeEvent)
void StartWalkAnimation();
void StartWalkAnimation_Implementation();
UFUNCTION(BlueprintNativeEvent)
void GoToThePoint(FVector _newPosition);
void GoToThePoint_Implementation(FVector _newPosition);
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
private:
FVector Waypoint;
};