I have a class Item and it has this logic
.h
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Item.generated.h"
UCLASS()
class LEADOFF_API AItem : public AActor
{
GENERATED_BODY()
public:
// Use item
UFUNCTION(/*BlueprintImplementableEvent*/BlueprintNativeEvent, BlueprintCallable, Category = "Item")
void Use();
UFUNCTION(BlueprintCallable, Category = "Item")
virtual void Use_Implementation();
};
.cpp
void AItem::Use_Implementation() {
UE_LOG(LogTemp, Warning, TEXT("Base use using"));
}
and I have an heir
.h
#include "CoreMinimal.h"
#include "Inventory/Item.h"
#include "DroppedItem.generated.h"
class LEADOFF_API ADroppedItem : public AItem
{
GENERATED_BODY()
protected:
AItem* BodyUse; // For use
public:
void Use();
virtual void Use_Implementation() override;
};
.cpp
void ADroppedItem::Use_Implementation() {
Super::Use_Implementation();
if (BodyUse) {
BodyUse->Use();
//BodyUse();
UE_LOG(LogTemp, Warning, TEXT("Good call BodyUse"));
}
else UE_LOG(LogTemp, Warning, TEXT("Bodyuse has nullptr"));
}
and also I have InputAction
UPROPERTY(EditAnywhere, Category = "EnhancedInput")
UInputAction* UseAction;
and bind them
Input->BindAction(UseAction, ETriggerEvent::Started, this, &AMainPlayer::UseItem);
in UseItem
if (InventoryComponent && InventoryComponent->HasInActiveSlot()) {
AItem* ActiveItem = InventoryComponent->/*GetItemInActiveSlot()*/GetItemInActiveSlot();
if (ActiveItem)
ActiveItem->Use();
UE_LOG(LogTemp, Warning, TEXT("Item use"));
}
else UE_LOG(LogTemp, Warning, TEXT("Bad item use"));
and the problem I have is that when I call ActiveItem->Use(); Nothing happens to me although it says UE_LOG(LogTemp, Warning, TEXT(“Item use”));
but the Use logic itself is not executed although it is overridden in Blueprint.
Blueprint has this logic:
why isn’t it called?