Implementing a UInterface in a UStruct c++

Hello,

I have just started learning Unreal and am trying to create a USTRUCT that implements a UINTERFACE

I have an Item struct:

USTRUCT(BlueprintType)
struct FAMINE_API FItem : public IInteractableInterface
{
	GENERATED_BODY()

public:
	UFUNCTION(BlueprintNativeEvent)
	virtual void Interact(class AActor* InteractingActor) override;

private:
	UPROPERTY(EditAnywhere, meta = (AllowPrivateAccess = "true"))
	class UItemDataAsset* ItemData;
};

and an Interactable UINTERFACE

UINTERFACE(MinimalAPI)
class UInteractableInterface : public UInterface
{
	GENERATED_BODY()

};

/**
 * 
 */
class FAMINE_API IInteractableInterface
{
	GENERATED_BODY()

	// Add interface functions to this class. This is the class that will be inherited to implement this interface.
public:
	virtual void Interact(class AActor* InteractingActor) = 0;
	
};

The problem is that the header tool expects the struct to inherit from another UStruct and then throws the following error at compile time:

Parent Struct ‘IInteractableInterface’ is missing a valid Unreal prefix, expecting ‘UInteractableInterface’

Is there any way to implement an interface in a UStruct? If not, is my only option then to switch to a UClass?

Thanks!

1 Like

Even if you’d do this the right way, you cannot have UFunctions inside UStruct because, for Unreal Engine, UStructs are value types.
Implementing an interface on a UStruct woudn’t work.

No, reflection system does not support interfaces in structs, as well as functions which is what you trying to do. But it should work in C++ as long as you not use U-macros on them and potentially you can make static Blueprints nodes to manageable them in Blueprint (for example make function in blueprint that calls struct function).