Interface-call conversion error?

if (HitResult.Actor->GetClass()->ImplementsInterface(UInteractableInterface::StaticClass()))
{
if (IInteractableInterface::Execute_CanInteract(HitResult.Actor, this)) // <<< error here
{
IInteractableInterface::Execute_Interact(HitResult.Actor, this); // <<< same error here
}

Gives an error on the “HitResult.Actor” saying:

error C2664: ‘bool
IInteractableInterface::Execute_CanInteract(UObject
*,APlayerCharacter *)’: cannot convert argument 1 from ‘AActor’ to ‘UObject
*’

I don’t understand that error. I must call the interface function on HitResult.Actor. So I gotta pass it as the parameter I suppose. But I am supposed to cast it to something before passing it or?

I also tried casting it but that resulted in more complex errors:

if (IInteractableInterface::Execute_CanInteract(Cast<IInteractableInterface>(HitResult.Actor), this))

Thanks. After looking at the differences between your code and mine all I had to do was replace:

Hitresult.Actor

with

Hitresult.GetActor()

This line:

  IInteractableInterface* const InteractInterface = Cast<IInteractableInterface>(HitResult.GetActor());

was not even required but does also work.

I think below should work. Can you try it out and let me know?

if (HitResult.Actor->GetClass()->ImplementsInterface(UInteractableInterface::StaticClass()))
{
    IInteractableInterface* const InteractInterface = Cast<IInteractableInterface>(HitResult.GetActor());

    if (InteractInterface->Execute_CanInteract(HitResult.GetActor(), this))
    {
        InteractInterface->Execute_Interact(HitResult.GetActor(), this);
    }
}