I am attempting to work with the UE4 Interfaces in C++ and, it seems like this should all work, I get no errors or compiler issues but I am getting results that make no sense. This is a very simple interface that should return a component from a character.
#include "CoreMinimal.h"
#include "UObject/ObjectMacros.h"
#include "UObject/Interface.h"
#include "InventoryInterface.generated.h"
class UInventoryComponent;
class AEquipmentItem;
// This class does not need to be modified.
UINTERFACE(BlueprintType)
class UInventoryInterface : public UInterface
{
GENERATED_BODY()
};
/**
*
*/
class SWORDSNMAGICANDSTUFF_API IInventoryInterface
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable, BlueprintIMplementableEvent, Category = "Inventory")
UInventoryComponent* GetInventoryComponent();
};
and then in the .h file for my character…
class SWORDSNMAGICANDSTUFF_API ASNMCombatCharacter : public ASNMCharacter, public IAbilitySystemInterface, public IInventoryInterface
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintImplementableEvent, BlueprintCallable, Category="Inventory")
UInventoryComponent* GetInventoryComponent();
virtual UInventoryComponent* GetInventoryComponent_Implementation();
and the .cpp
UInventoryComponent* ASNMCombatCharacter::GetInventoryComponent_Implementation()
{
return InventoryComponent;
}
Yet this always returns null, I am positive the class has the component which is stored in that variable.
This is where it is created in the parent class.
InventoryComponent = CreateDefaultSubobject<UInventoryComponent>(TEXT("Player Inventory"));
I have tried several methods to pull this info through the interface and they all return null.