Variables in Unreal c++ Interfaces not showing up in blueprint

Hi! I’m trying out interfaces in Unreal c++ and seeing what I can do with them.

My setup right now is really simple:

I have a blueprint class: TemporaryBlueprint
TemporaryBlueprint is a child of ATemporaryActor (c++ class)
ATemporaryActor is a child of Actor, and IMyInterface (c++ class)

MyInterface.h

#pragma once

#include "CoreMinimal.h"
#include "UObject/Interface.h"
#include "MyInterface.generated.h"

// This class does not need to be modified.
UINTERFACE(MinimalAPI)
class UMyInterface : public UInterface
{
	GENERATED_BODY()
};

/**
 * 
 */
class DEVSPACE_API IMyInterface
{
	GENERATED_BODY()

	// Add interface functions to this class. This is the class that will be inherited to implement this interface.
public:
	UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category = "From|Interface")
		bool TestEvent();

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "From|Interface", meta = (AllowPrivateAccess = "true"))
		bool InterfaceVariable;
};

TemporaryActor.h:

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "MyInterface.h"
#include "TemporaryActor.generated.h"

UCLASS()
class DEVSPACE_API ATemporaryActor : public AActor, public IMyInterface
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actor's properties
	ATemporaryActor();

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

public:	
	// Called every frame
	virtual void Tick(float DeltaTime) override;

protected:
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "From|Child", meta = (AllowPrivateAccess = "true"))
		bool abcd;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "From|Child", meta = (AllowPrivateAccess = "true"))
		bool efgh;
};

The blueprint class does show every variable from ATemporaryActor, but not from IMyInterface.

Is this impossible, or am I missing something?

i think you need to do it like this :

UINTERFACE(MinimalAPI, Blueprintable)

1 Like

I don’t beleive they can have properties. That is not their function. An Interface’s role is to enforce function implementation on the class that implements them.

Put your properties in a base class and use inheritence, if you want specific uproperties in a class.

1 Like

This sounds like it should work but sadly doesn’t.

Dang, I suspected as much.
I just now found this thread that seems to confirm it: Member Variable Declaration not allowed in Interfaces?

Thanks btw! I’ll tinker around and see what solution I’ll come up with.

Just add getter/setter functions

protected:
    bool abcd;
public:
    UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
    bool GetAbcd();
    virtual bool GetAbcd_Implementation() { return abcd; }
    UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
    void SetAbcd(bool b);
    virtual void SetAbcd_Implementation(bool b) { abcd = b; }

This will not work if you implement the interface in Blueprint for two reasons:

  1. The variable will not be part of the Blueprint Generated Class
  2. Default UFUNCTION event implementations will not ever be called.

True, but it works just fine if you implement interface in C++ class.

You can even override the BlueprintNativeEvents in BP child classes, and use “call parent function” from there, so you can add BP logic to the setter.