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++?