I have a base class of weapons that implements the interface: SWeapon
From it the class is inherited: SFireWeapon
The problem is that the interface function called in SWeapon is not called in its successor SFireWeapon
Код:
SWeapon .h
#pragma once
#include "SInteractInterface.h"
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "SWeapon.generated.h"
UCLASS()
class SONLINE_API ASWeapon : public AActor, public ISInteractInterface
{
GENERATED_BODY()
public:
UFUNCTION()
virtual bool Interact_Implementation() override;
};
SWeapon .cpp
bool ASWeapon::Interact_Implementation()
{
if (GEngine)
{
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Green, TEXT("WeaponEqip"));
}
return true;
}
SInteractInterface .h
UINTERFACE(Blueprintable)
class USInteractInterface : public UInterface
{
GENERATED_BODY()
};
/**
*
*/
class SONLINE_API ISInteractInterface
{
GENERATED_BODY()
// Add interface functions to this class. This is the class that will be inherited to implement this interface.
public:
UFUNCTION(BlueprintCallable,BlueprintNativeEvent, Category = "Interact")
bool Interact();
};
SOnlineCharacter .cpp
FHitResult HitInteract;
if (GetWorld()->LineTraceSingleByChannel(HitInteract, TraceStart , TraceEnd, ECC_Visibility, QueryParams))
{
AActor* HitActor = HitInteract.GetActor();
ISInteractInterface* InteractInterface = Cast<ISInteractInterface>(HitActor);
if (InteractInterface)
{
InteractInterface->Execute_Interact(HitActor);
DrawDebugLine(GetWorld(), TraceStart, HitInteract.ImpactPoint, FColor::Green, false, 5.0f, 0, 1.0f);
if (GEngine)
{
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Green, TEXT("Interfaceinteract true"));
}
}