Hi,
I’ve got slightly stuck and although searching has revealed people with all sorts of problems around this area, I haven’t seen anyone trying to do exactly this.
I have an interface defined in C++:
UINTERFACE(BlueprintType)
class UGenerator : public UInterface
{
GENERATED_BODY()
};
class XXX_API IGenerator
{
GENERATED_BODY()
// Add interface functions to this class. This is the class that will be inherited to implement this interface.
public:
...
};
At the moment there isn’t anything in that bottom “…” section (I only want to identify the inheriting actor types as suitable for passing to other C+±level methods…)
But if I add a UFUNCTION in there it doesn’t seem to change my problem, so I do not think this about empty interfaces.
I implement this in C++ too:
UCLASS(BlueprintType)
class XXX_API ACubeGenerator : public AActor, public IGenerator
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
ACubeGenerator();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
... etc ...
};
Which seems to work happily…
However then I move to Blueprints and try to use this. I create a variable on a blueprint of type “Generator” and that also works. However, in level editing, when I try to set that variable, it won’t take actors of type “Cube Generator”…
I am thinking what I’m missing is something to tell the reflection system that “Cube Generator” implements “Generator”? e.g. the C++ is aware of that, because of inheriting IGenerator, but there isn’t anything specifying the same link between ACubeGenerator and UGenerator. I thought there might be an optional argument for UCLASS, maybe something like “Implements=” but I haven’t so-far found anything…
Can this be done? I guess the alternative is to make the variable just of type Object and cast that to the interface before use, however there doesn’t seem to be any point to blueprint variables of interface types if they cannot be populated with different implementations?
Thanks!
Ian