I’m having trouble understanding how to properly call an interface function in C++ from blueprint objects that don’t implement the interface in code, but rather in the blueprint editor.
In general I’m using this method right now to call interface function of classes that implement the interface via code.
for (TObjectIterator<UObject> Object; Object; ++Object)
{
// Check if the object implements the interface
if (Object->Implements<UMyInterface::ThisClass>())
{
if (!IsValid(*Object)) continue;
if (Object->IsEditorOnly()) continue;
if (Object->HasAnyFlags(RF_ArchetypeObject | RF_ClassDefaultObject | RF_NeedInitialization | RF_DefaultSubObject | RF_Transient)) continue;
TScriptInterface<IMyInterface> Interface = *Object;
if (Interface)
{
Interface->SaveOwningObject();
}
else
{
UE_LOG(LogTemp, Warning, TEXT("Object %s does not implement the interface"), *Object->GetName())
}
}
}
From what I understand TScriptInterface will only work with classes that implement the interface in code because it uses vtable lookup to find the interface address. Blueprint classes do not have this luxury, so how can we call those interface function on those classes?
Also, I’m not trying to do Execute_FunctionName but rather to call a virtual function in the interface, not a UFUNCTION().
All input welcome!