Executing overridden blueprint interface functions from C++?

I am having a problem trying to call a method on an interface from c++ to invoke and overridden function in a blueprint class.

  • Define interface in C++; IHelp with one method named bool Test()
  • Define actor in C++; Foo that inherits IHelp
  • Derive blueprint actor from Foo; Boo
  • Override bool Test() as a function in Boo
  • I add Boo to the level and then call a function Library method which invokes IHelp → Test() on Boo. the function library is written in C++.
  • Boo
    does implement the interface
    without any problem executes
    But … the overridden function never gets called?

I have tried everything with no success.
I think this post describe the problem I’m having, but I have tried all of the tips and it still does not work.

Any advice would be appreciated!

You need to call your function with Execute_ prefix which will call blueprint if function id overrided so Execute_Test(). It’s a function generated by UHT.

Hi Shadow, I was doing that. I’m going to redo the class do a simple test example and try it again. I will post the code and results. much appreciated you hanging in there and trying to help me. :slight_smile:

It works! I honestly think I must be losing my mind because I tried this so many times doing the exact same thing and it never worked before. For the sake of being complete and documenting the solution for others who may be struggling here is my code . thanks again shadow!

lockable.h

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

/**
 * 
 */
class EMBER_API ILockable
{
	GENERATED_BODY()

	// Add interface functions to this class. This is the class that will be inherited to implement this interface.
public:
	UFUNCTION(BlueprintImplementableEvent, BlueprintCallable, Category = "Lockable")
		void Lock(const FString &key);
};

lockingactor.h

UCLASS()
class EMBER_API ALockingActor : public AActor, public ILockable
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actor's properties
	ALockingActor();

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

public:	
	// Called every frame
	virtual void Tick(float DeltaTime) override;
	
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		FString key = FString();

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		bool isLocked = false;


};

test lock

void UFunctionLibrary::TestLock(AActor * actor)
{
	if (actor->GetClass()->ImplementsInterface(ULockable::StaticClass()))
	{
		FGuid guid = FGuid::NewGuid();
		ILockable::Execute_Lock(actor, guid.ToString());
	}
}

Create a blueprint based on locking actor, and then implement the Event Lock.
When you call the Execute_Lock function in your C++ Code the blueprint event will be called.

Good luck!