Interface C++ How to call parent interface function.

Hello I’m struggling to get interface inheritance work. I simplified the problem, let’s say that we have this interface:


UINTERFACE(BlueprintType)
class UAInterface : public UInterface
{
    GENERATED_BODY()
};

class IAInterface
{    
    GENERATED_BODY()
public:

    UFUNCTION(BlueprintNativeEvent, BlueprintCallable)
    void OnSomething();



Now this component that implements the interface prints the HELLO WORLD text:





UCLASS(Blueprintable, BlueprintType)
class UComponentA: public IAInterface {
    GENERATED_BODY()
public:

    virtual void OnSomething_Implementation() override { 
      UE_LOG(LogTemp, Warning, TEXT("HELLO WORLD"));
    }

};




Now the concrete component that inherits from UComponentA and extends the functionallity:





UCLASS(Blueprintable, BlueprintType)
class UComponentB: public UComponentA {
    GENERATED_BODY()
public:

    virtual void OnSomething_Implementation() override { 
HOW TO CALL THE INTERFACE FUNCTION OF THE SUPER CLASS (UComponentA) to output first the HELLO WORLD text???
      //Super::OnSomething();  <-- this crashes with: Do not directly call Event functions in Interfaces. Call Execute_OnSomething instead
      // If I use Execute_OnSomething( UObject* )      it needs a pointer to the Super class i think.. how to retrieve it?

      UE_LOG(LogTemp, Warning, TEXT("I'M THE COMPONENT B!!! "));
    }

};




Is the red line possible to do? How exactly?
Thank you!

Maybe taking a look into any UE class source code might bring light to this, but from the look I think the decorator is not correct, it should be BlueprintImplementableEvent instead of BlueprintNativeEvent… Im not in a place where I can access the code, but I would look at how AActor code looks like as a reference.

When overriding _Implementation functions, you’re supposed to call Super::MyFunction_Implementation() - NOT Super::MyFunction(). If you don’t, bad things will happen. Try that first, and you won’t need the parameter either.

If that doesn’t work, then I don’t think it’s possible to call Super in an interface function exposed to Blueprint. C++ functions should work fine though, I think.

Calling the Execute function on a “Super Class” won’t really help you because A) it needs to be called on an instance, not a class - and B) you’ll end up calling it on a class-default object, not an instance of an object.

2 Likes

Thank you TheJamsh!! It works perfect with _Implementation(); :slight_smile:

Hi! Roig.

In first post you use UINTERFACE(BlueprintType).

But more correct keyword for UINTERFACE(Blueprintable).

Check: UE_4.19\Engine\Source\Runtime\CoreUObject\Public\UObject*ObjectMacros.h*
line: ~730



namespace UI
{
    // valid keywords for the UINTERFACE macro, see the UCLASS versions, above
    enum
    {
        /// This keyword indicates that the interface should be accessible outside of it's module, but does not need all methods exported.
        /// It exports only the autogenerated methods required for dynamic_cast<>, etc... to work.
        MinimalAPI,

        /// Exposes this interface as an acceptable base class for creating blueprints. The default is NotBlueprintable, unless inherited
        otherwise. This is inherited by subclasses.
        Blueprintable,

        /// Specifies that this interface is *NOT* an acceptable base class for creating blueprints. The default is NotBlueprintable, unless
        inherited otherwise. This is inherited by subclasses.
        NotBlueprintable,

        /// Sets IsConversionRoot metadata flag for this interface.
        ConversionRoot,
    };
}


Make your UE4 code more clear! :wink:

Thank you Andrew2015!!

UE4 needs better documentation… >_<

Here it says BlueprintType in the table… argggh, is it valid or not for interfaces?

I’m glad to help! I think a typo in the table. I trust the code comments more .)