# Calling Interface Functions In C++

**URL:** <https://forums.unrealengine.com/t/calling-interface-functions-in-c/323521>\
**Category:** UI\
**Tags:** interface, unreal-engine, question, CPP\
**Created:** [June 30, 2015, 5:25am UTC](https://forums.unrealengine.com/t/calling-interface-functions-in-c/323521 "2015-06-30T05:25:23Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![pdenton](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/pdenton/32/911626_2.png) [@pdenton](https://forums.unrealengine.com/u/pdenton)\
**Post date:** [January 14, 2024, 9:47pm UTC](https://forums.unrealengine.com/t/calling-interface-functions-in-c/323521/9 "2024-01-14T21:47:04Z")

</div>

I came across this topic when trying to solve a specific UInterface related issue and I thought I might add one important thing to the discussion.

There are actually 2 scenarios in which we’re calling UInterface functions in C++:

1. When interface is inherited by C++ class
2. When interface is added in the blueprint Class Settings

Each of those requires different handling in C++ when calling an interface function.  
First scenario:

```auto
if (Cast<IInterface_MyInterface>(MyActor))
{
	Cast<IInterface_MyInterface>(MyActor)->Execute_MyInterfaceFunction(MyActor);
}

```

Second scenario (Note UInterface in the if statement and IInterface in the function call!):

```auto
if (MyActor->GetClass()->ImplementsInterface(UInterface_MyInterface::StaticClass()))
{
	IInterface_MyInterface::Execute_MyInterfaceFunction(MyActor);
}

```

Perhaps someone will find this information useful.

EDIT: as “ImplementsInterface” seems to work in both scenarios (interface inherited in C++ and interface added in the Blueprint) I’d say it should be a preferred method for checking if an Actor implements a given interface.

---

_[View the full topic](https://forums.unrealengine.com/t/calling-interface-functions-in-c/323521)._
