Finding all actors which inherit an interface, and call a corresponding interface function in C++?

In version 4.8.3, I have a blueprint function library which needs to be converted into C++.
Currently, there is only one function in this blueprint library.
The part I’m having trouble with can be seen highlighted here:

Basically, I need to get an array of all actors which implement the Marionettist interface, then call a function on that interface.
Here’s what I’ve got so far…

MarionettistUtilities.h:


UCLASS(Blueprintable)
class UMarionettistUtilities : public UBlueprintFunctionLibrary
{
	GENERATED_UCLASS_BODY()

public:
	UFUNCTION(BlueprintCallable, Category = "Default")
	static void FindMarionettistInScene(TEnumAsByte<EMarionettist> MarionettistName, bool &Error, TScriptInterface<IMarionettistInterface> &Interface);
};

MarionettistUtilities.cpp:


void UMarionettistUtilities::FindMarionettistInScene(TEnumAsByte<EMarionettist> MarionettistName, bool &Error, TScriptInterface<IMarionettistInterface> &Interface)
{
	TArray<AActor*> Actors;
	UGameplayStatics::GetAllActorsWithInterface(GWorld, UMarionettistInterface::StaticClass(), Actors);

	for (auto a : Actors)
	{
		if (!a->Implements<UMarionettistInterface>())
			continue;

		auto ifc = Cast<IMarionettistInterface>(a);
		if (!ifc) continue;
		auto name = ifc->Execute_GetWorldUniqueMarionettistName(Cast<UObject>(a));

		if (name == MarionettistName) {
			if (IsValid(ifc->_getUObject())) {
				Error = false;
				Interface.SetInterface(ifc);
				return;
			}
		}
	}

	Error = true;
}

The main issue here is that the cast on line #11 always returns NULL, even though I’m 100% positive that the actor in question inherits the correct interface.
I know this because I checked the name of the actors, and they are indeed classes which inherit IMarionettistInterface in their blueprints, implemented in their parent blueprint.
Plus, the check for Implements<UMarionettistInterface> on line #8 always passes for the objects in question.

Can anybody tell me what I’m doing wrong? How can I utilize this interface in C++?

TScriptInterface only works with classes which inherit the interface natively (ie. if it’s a blueprint class, it must be a descendant of a C++ class which derives from IMarionettistInterface).
When you implement an interface by adding it in a blueprint, tests like Implements() will return true, but you can’t cast your object to the interface type. If you need to work with classes that may have inherited the interface in blueprint, then you can call the interface functions as follows (this will work for natively implemented interfaces too):



auto name = IMarionettistInterface::Execute_GetWorldUniqueMarionettistName(MyActor);


In this case, I’m not sure that there is currently any way to pass it back to blueprint as an interface. I think you’d need to just return the actor, and then convert it to an interface in the blueprint if necessary.