Return From Interface Function Returning Null

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.

Further testing shows it doesnt seem to actually be calling the function on the character class. Documentaion on Interfaces in C++ seem to be pretty contradictory to reality. When attempting to add override to this which is show in EVERY doc it fails to compile.

In your implementation, you don’t have to re-state the UFUNCTION macro nor the original getter… but you must do the _Implementation, like you have done.
However, one thing you’re missing is the override specifier at the end of your function declaration.

Perhaps something like:

class SWORDSNMAGICANDSTUFF_API ASNMCombatCharacter : public ASNMCharacter, public IAbilitySystemInterface, public IInventoryInterface
 {
     GENERATED_BODY()
         
 public:
     virtual UInventoryComponent* GetInventoryComponent_Implementation() override;

I dropped the UFUNCTION and the getter, then added the override specifier at the end.

Good luck!

ill give this a try!

Part of the problem was a typo in the original code so it was not implementing the interface UFUNCTION properly, but outside of that this answer was correct, and provides a cleaner implementation with less funk.