Hello guys,
My actor is not destroyed. It inherited from another custom class (AAmmo : public AItem)
AMMO.H
UCLASS()
class AAmmo : public AItem
{
GENERATED_BODY()
public:
AAmmo();
virtual void BeginPlay() override;
UFUNCTION()
virtual void OnCollisionBeginOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
UFUNCTION()
virtual void OnCollisionEndOverlap(UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);
};
AMMO.CPP
void AAmmo::OnCollisionBeginOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
if ((OtherActor != nullptr) && (OtherActor != this) && (OtherComp != nullptr))
{
auto Character = Cast< AMedievalCharacter >(OtherActor);
if (Character)
{
if (IsValid(Character->GetComponentByClass(UInventoryComponent::StaticClass())))
{
auto component = Character->GetComponentByClass(UInventoryComponent::StaticClass());
UInventoryComponent* inventory = Cast<UInventoryComponent>(component);
if (inventory)
{
if (inventory->AddItem(1, this))
{
GEngine->AddOnScreenDebugMessage(-1, 1.f, FColor::Green, FString::Printf(TEXT("You hit this but object not destroyed: %d"), inventory->SearchEmptySlot()));
Super::Destroy();
}
}
}
}
}
}
ITEM.H
UCLASS(Abstract, Blueprintable)
class AItem : public AActor
{
GENERATED_BODY()
public:
AItem();
virtual void BeginPlay() override;
virtual void Tick(float DeltaTime) override;
//virtual void OnCollisionBeginOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
//virtual void OnCollisionEndOverlap(UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);
UFUNCTION(BlueprintImplementableEvent)
void EventOnUsed();
FItemInfo GetItemInfo() { return ItemInfo; }
protected:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FItemInfo ItemInfo;
UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
class UBoxComponent* BoxCollision;
UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
class USkeletalMeshComponent* SKMesh;
UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
class UStaticMeshComponent* Mesh;
};
Do you have any idea why is that happening?