Hi Everyone,
I am not sure what I am doing wrong here. When I try to make a call to the function AffectHealth, I get a crash. I have tried casting the object using Cast (As seen below) and InterfaceCast<>.
This is where the function where the crash occurs:
void AWeapon::NotifyActorBeginOverlap(AActor* OtherActor)
{
IDamageable* damageableActor = Cast<IDamageable>(OtherActor);
// Check if this actor is damageable
if (damageableActor)
{
// THIS IS WHERE THE CRASH Happens
damageableActor->AffectHealth();
}
}
This is the interface defined in C++:
UINTERFACE(BlueprintType)
class HSROUGE_API UDamageable : public UInterface
{
GENERATED_BODY()
};
class HSROUGE_API IDamageable
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "DamageSystem")
void AffectHealth();
};
Base character class implementing the Interface:
UCLASS()
class ABaseCharacter : public ACharacter, public IDamageable
{
.
.
.
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = “DamageSystem”)
void AffectHealth();
virtual void AffectHealth_Implementation();
.
.
.
}
void ABaseCharacter::AffectHealth_Implementation()
{
UE_LOG(LogTemp, Warning, TEXT("I %s health is affected From BaseCharacter Class"), *this->GetName());
}