How to pass arg. to a function as an instance of interface type?

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

I ran into a similar issue and it turned out I hadn’t implemented the declarations of the functions in the interface header properly. I didn’t need any BP exposed functionality on my interface. To have a native c++ interface function that you don’t need in BP you need to declare your interface function as pure virtual. For example:

class IInterfaceName
{
GENERATED_BODY()
virtual float InterfaceFunction() const PURE_VIRTUAL(IInterfaceName::InterfaceFunction, return 1.f;);
}

Then you still need the UInterface wrapper for it as well. Not sure if this is the same problem you were experiencing but I ran into this thread on my way to solving it so figured I would leave my solution here either way.