# C++ Interfaces - Execute\_FunctionName() vs FunctionName\_Implementation()

**URL:** <https://forums.unrealengine.com/t/c-interfaces-execute-functionname-vs-functionname-implementation/770619>\
**Category:** C++\
**Tags:** unreal-engine, question\
**Created:** [February 14, 2023, 3:27pm UTC](https://forums.unrealengine.com/t/c-interfaces-execute-functionname-vs-functionname-implementation/770619 "2023-02-14T15:27:41Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Auticus.Daerk](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/auticus.daerk/32/553980_2.png) [@Auticus.Daerk](https://forums.unrealengine.com/u/Auticus.Daerk)\
**Post date:** [February 14, 2023, 3:27pm UTC](https://forums.unrealengine.com/t/c-interfaces-execute-functionname-vs-functionname-implementation/770619/1 "2023-02-14T15:27:42Z")

</div>

Interfaces are probably for me one of the most clunky implementations in the Unreal framework in my opinion.

Straight question. I have a class called Foo. Foo has a function called DoThis().  
I have an interface called IFooable which has a function DoThis();

Foo implements IFooable.

I know that in unreal I can’t say MyIFooObject-\>DoThis() (where MyIFooObject is an Interface variable). However… this is where I need some guidance because I can’t find a straight answer.

The way I learned unreal was I had to do MyIFooObject-\>DoThis\_Implementation(); This seems fine but I also see the compiler sometimes throw and tell me I need to use MyIFooObject-\>Execute\_DoThis() instead.

What are the differences here, and when should I use which?

---

<div class="post-metadata">

**Author:** ![MagForceSeven](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/magforceseven/32/906563_2.png) [@MagForceSeven](https://forums.unrealengine.com/u/MagForceSeven)\
**Post date:** [February 14, 2023, 3:57pm UTC](https://forums.unrealengine.com/t/c-interfaces-execute-functionname-vs-functionname-implementation/770619/2 "2023-02-14T15:57:21Z")

</div>

One is for calling the function one is for implementations.

Foo should override `DoThis_Implementation`, but you should never directly call an \_Implementation function except as a Super:: call to include functionality from the parent type.

The Execute\_ version is used to call the function and deals with all the annoying details with Blueprint implementations. You should call this like: `IFooable::Execute_DoThis( Object )`. That object shouldn’t be an interface variable, just a UObject\* (or something convertible to one).

Lastly, if an interface could be implemented by Blueprint, you’ll need to avoid having interface variables like MyIFooObject because `Cast<IFooable>( )` will return nullptr when the interface is implemented in blueprint. Instead you’ll have to use `TScriptInterface<IFooable>` as the type.

> [@Auticus.Daerk](#):
>
> Interfaces are probably for me one of the most clunky implementations in the Unreal framework in my opinion.

I don’t disagree, it’s all Blueprint’s fault. 😉

---

<div class="post-metadata">

**Author:** ![eblade](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@eblade](https://forums.unrealengine.com/u/eblade)\
**Post date:** [February 14, 2023, 5:10pm UTC](https://forums.unrealengine.com/t/c-interfaces-execute-functionname-vs-functionname-implementation/770619/3 "2023-02-14T17:10:34Z")

</div>

> [@MagForceSeven](#):
>
> Foo should override `DoThis_Implementation`, but you should never directly call an \_Implementation function except as a Super:: call to include functionality from the parent type.

There could be reasons why you specifically want to call the native implementation rather than call into the Blueprint, although I would expect they would be few and far between, but I wouldn’t say _never_.

I don’t know if maybe this has been fixed/changed in the time since this document was written, but it seems like it’s better to actually call IInterface::Execute\_Whatever(ObjectPointer), as apparently TScriptInterface does suffer from the same issue as just trying to use a Cast … unless that has changed since this was written:

> **[UE4 C++ Interfaces - Hints n Tips · SteveStreeting.com](https://www.stevestreeting.com/2020/11/02/ue4-c---interfaces---hints-n-tips/)**
>
> Tutorial on how to use interfaces defined in C++ in UE4, with some useful practical tips

---

<div class="post-metadata">

**Author:** ![Auticus.Daerk](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/auticus.daerk/32/553980_2.png) [@Auticus.Daerk](https://forums.unrealengine.com/u/Auticus.Daerk)\
**Post date:** [February 14, 2023, 5:20pm UTC](https://forums.unrealengine.com/t/c-interfaces-execute-functionname-vs-functionname-implementation/770619/4 "2023-02-14T17:20:14Z")

</div>

Yep I ran into the TScriptInterface fun a little while back. I have gotten into the habit of working with UObject\* now when I have interfaced objects simply because the editor doesn’t barf over that. I have some TScriptInterface pieces being used, mainly just to hold references to objects that I expose as property in blueprint.

In this case almost my entire project is C++ code and I don’t really use blueprinting. The confusing is when I watch tutorials, so many people are teaching to use the \_implementation version, which does work just fine in my project… but I see Execute\_FunctionName() as well and wonder why there are two ways to do the same thing.

But I see it has to do with blueprints. Maybe my code works fine because its mostly C++ and doesn’t use blueprints except for things like materials.

---

<div class="post-metadata">

**Author:** ![MagForceSeven](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/magforceseven/32/906563_2.png) [@MagForceSeven](https://forums.unrealengine.com/u/MagForceSeven)\
**Post date:** [February 14, 2023, 6:56pm UTC](https://forums.unrealengine.com/t/c-interfaces-execute-functionname-vs-functionname-implementation/770619/5 "2023-02-14T18:56:21Z")

</div>

> [@eblade](#):
>
> but I wouldn’t say _never_.

Yeah, always and never can be pretty loaded. You’d need a pretty good reason for it.

> [@eblade](#):
>
> but it seems like it’s better to actually call IInterface::Execute\_Whatever(ObjectPointer)

Oh absolutely, the TScriptInterface does not provide any better access to the functions. It’s just for variables and you’d want to get the object from the variable to call ::Execute\_. But it’s the type you’d have to use to properly restrict a function parameter that’s callable by blueprint.

> [@Auticus.Daerk](#):
>
> as well and wonder why there are two ways to do the same thing.

Because they’re not two ways to do the _same_ thing. There’s one way to implement the interface (overriding the \_Implementation function) and one way to call it (using the static Execute function).

> [@Auticus.Daerk](#):
>
> n this case almost my entire project is C++ code and I don’t really use blueprinting.

In that case you do have another option. In the UINTERFACE macro you can include `meta=(CannotImplementInterfaceInBlueprint)`, this will prevent implementations in Blueprint and a lot of the weirdness that causes. Once you’ve done that, at least in C++, you can treat the interface as you would expect: declaring and overriding virtual functions (no \_Implementation functions needed), casting to IFooable\* works as expected in all cases, you can call the functions directly with a pointer to the interface and you can even make the functions BlueprintCallable to still use in Blueprint.

---

<div class="post-metadata">

**Author:** ![Auticus.Daerk](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/auticus.daerk/32/553980_2.png) [@Auticus.Daerk](https://forums.unrealengine.com/u/Auticus.Daerk)\
**Post date:** [February 14, 2023, 7:16pm UTC](https://forums.unrealengine.com/t/c-interfaces-execute-functionname-vs-functionname-implementation/770619/6 "2023-02-14T19:16:09Z")

</div>

> [@MagForceSeven](#):
>
> Because they’re not two ways to do the _same_ thing. There’s one way to implement the interface (overriding the \_Implementation function) and one way to call it (using the static Execute function).

This may be my ignorance from years and years in C# speaking here. In C# when I implement an interface, i simply say IInterfaceableObject.DoThis() and it executes the DoThis() function on the base object.

In Unreal i say IInterfaceableObject-\>DoThis\_Implementation() and it seems to execute the DoThis() function on the object.

In Unreal if I say IInterfaceableObject-\>Execute\_DoThis() it also seems to execute the DoThis() function which is where I drew that conclusion.

> [@MagForceSeven](#):
>
> In that case you do have another option. In the UINTERFACE macro you can include `meta=(CannotImplementInterfaceInBlueprint)`, this will prevent implementations in Blueprint and a lot of the weirdness that causes. Once you’ve done that, at least in C++, you can treat the interface as you would expect: declaring and overriding virtual functions (no \_Implementation functions needed), casting to IFooable\* works as expected in all cases, you can call the functions directly with a pointer to the interface and you can even make the functions BlueprintCallable to still use in Blueprint.

I’ll check that out. That seems to be the direction I want to go.

My project works right now via using the \_Implementation() functions, I am just wondering why I’d use one over the other. It seems the answer is blueprints cause some craziness.

---

<div class="post-metadata">

**Author:** ![eblade](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@eblade](https://forums.unrealengine.com/u/eblade)\
**Post date:** [February 14, 2023, 7:49pm UTC](https://forums.unrealengine.com/t/c-interfaces-execute-functionname-vs-functionname-implementation/770619/7 "2023-02-14T19:49:09Z")

</div>

> [@Auticus.Daerk](#):
>
> My project works right now via using the \_Implementation() functions, I am just wondering why I’d use one over the other. It seems the answer is blueprints cause some craziness.

it’s my understanding that if you call \_Implementation you’re only calling the native code, not any potential Blueprint overrides.

---

<div class="post-metadata">

**Author:** ![Auticus.Daerk](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/auticus.daerk/32/553980_2.png) [@Auticus.Daerk](https://forums.unrealengine.com/u/Auticus.Daerk)\
**Post date:** [February 14, 2023, 7:52pm UTC](https://forums.unrealengine.com/t/c-interfaces-execute-functionname-vs-functionname-implementation/770619/8 "2023-02-14T19:52:09Z")

</div>

> [@eblade](#):
>
> it’s my understanding that if you call \_Implementation you’re only calling the native code, not any potential Blueprint overrides.

Thank you, that makes a ton of sense. If I were using Blueprints I can see why I’d want to call Execute in that case. As I’m not using Blueprints that won’t make a difference to me.

1000 thanks.

---

<div class="post-metadata">

**Author:** ![eblade](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@eblade](https://forums.unrealengine.com/u/eblade)\
**Post date:** [February 14, 2023, 7:54pm UTC](https://forums.unrealengine.com/t/c-interfaces-execute-functionname-vs-functionname-implementation/770619/9 "2023-02-14T19:54:11Z")

</div>

If you go that route, remember that months down the road when you think “oh, hey, i can just override this thing real quick in blueprint” and then nothing overrides 😃

---

<div class="post-metadata">

**Author:** ![Auticus.Daerk](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/auticus.daerk/32/553980_2.png) [@Auticus.Daerk](https://forums.unrealengine.com/u/Auticus.Daerk)\
**Post date:** [February 14, 2023, 8:02pm UTC](https://forums.unrealengine.com/t/c-interfaces-execute-functionname-vs-functionname-implementation/770619/10 "2023-02-14T20:02:42Z")

</div>

I’m one of those weird people that doesn’t like blueprints if I don’t have to use them, and prefer doing everything I can in pure code. However sometimes I’ve noticed I don’t have a choice so what you are saying is sage, because I can see that coming up should I have to go a blueprint route for whatever reason and trying to call interface functions that suddenly won’t override heh.
