I’m trying to pass an pawn of class (AMyPawn), inherited also from an interface (IMyInterface, which have specific method called InterfaceFunction()
) to an actor-component method in this way:
//! MyPawn.h
UCLASS(Blueprintable)
class AMyPawn : public APawn, public IMyInterface
{
GENERATED_UCLASS_BODY()
...
}
//! UMyComponent.cpp
void UMyComponent::Func(TScriptInterface<IMyInterface> argumentActor)
{
/*
* get argument actor as ptr to IMyInterface
* instance and call specific interfce method:
*/
argumentActor->InterfaceFunction();
...
}
//! place of calling in some cpp:
void SomeClass::SomeMethod(AMyPawn* myPawn)
{
...
MyComponentInstance->Func(Cast<IMyInterface>(myPawn));
...
}
But with this code I get compile-error:
>C:\MyProject\dev\Engine\Source\Runtime\CoreUObject\Public\UObject\ScriptInterface.h(144): error C2664: 'void FScriptInterface::SetObject(UObject *)' : cannot convert argument 1 from 'IMyInterface *' to 'UObject *'
>Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast